JavaScript Quiz
Table of contents
- Q1. ๋ณ์ ํธ์ด์คํ ๊ณผ ์ผ์์ ์ฌ๊ฐ์ง๋
- Q2. var์ let ์ผ๋ก ์ ์ธ๋ ๋ณ์์ ์ค์ฝํ
- Q3. ํ์ดํ ํจ์์ this
- Q4. ์๋ฌต์ ํ์ ๋ณํ
- Q5.
- Q6.
- Q7.
- Q8.
- Q9.
- Q10.
- Q11.
- Q12.
- Q13. ์ด๋ฒคํธ ์ ๋ฌ์ 3๋จ๊ณ๋ ๋ฌด์์ผ๊น์?
- Q14. ๋ชจ๋ ๊ฐ์ฒด๋ ํ๋กํ ํ์ ์ ๊ฐ์ ธ์.
- Q15.
- Q16.
- Q17.
- Q18.
- Q19.
- Q20.
- Q21. sum์ ๊ฐ์ ๋ฌด์์ผ๊น์?
- Q22. cool_secret์ ๋ช ์๊ฐ์ด๋ ์ ๊ทผ์ด ๊ฐ๋ฅํ ๊น์?
- Q23.
- Q24.
- Q25.
- Q26. JavaScript์ global execution context๋ ๋๊ฐ๋ฅผ ์์ฑํด์. : ์ ์ญ๊ฐ์ฒด์ "this" ํค์๋์์.
- Q27.
- Q28.
- Q29.
- Q30.
- Q31. ๋ฒํผ์ ํด๋ฆญํ์๋ event.target์ ๋ฌด์์ผ๊น์?
- Q32. p ํ๊ทธ๋ฅผ ํด๋ฆญํ๋ฉด ๋ก๊ทธ์ ์ถ๋ ฅ์ ๋ฌด์์ผ๊น์?
- Q33.
- Q34.
- Q35. ์ด ๊ฐ๋ค ์ค ์ด๋ ๊ฒ์ด ๊ฑฐ์ง ๊ฐ์ ๊ฐ ์ผ๊น์?
- Q36.
- Q37.
- Q38.
- Q39. JavaScript์ ๋ชจ๋ ๊ฒ์...
- Q40.
- Q41.
- Q42. setInterval ๋ฉ์๋๋ ๋ธ๋ผ์ฐ์ ์๊ฒ ๋ฌด์์ ๋ฆฌํด ํ ๊น์?
- Q43.
- Q44.
- Q45.
- Q46.
- Q47.
- Q48.
- Q49. num์ ๊ฐ์ ๋ฌด์์ผ๊น์?
- Q50.
- Q51.
- Q52.
- Q53.
- Q54.
- Q55.
- Q56.
- Q57.
- Q58.
- Q59.
- Q60.
- Q61.
- Q62.
- Q63.
- Q64.
- Q65.
- Q66. Dog ํด๋์ค๋ฅผ ์ฑ๊ณต์ ์ผ๋ก ํ์ฅํ ์ ์๋ ์์ฑ์๋ ์ด๋ ๊ฒ์ผ๊น์?
- Q67.
- Q68.
- Q69.
- Q70.
- Q71. console.log ํํ์ ๋ค์ ์ธ๊ธ๋ ๊ฐ์ ์ด๋ป๊ฒ ์ถ๋ ฅํ ์ ์์๊น์?
- Q72.
- Q73.
- Q74.
- Q75.
- Q76.
- Q77. ์ด๊ฒ์ pure ํจ์ ์ผ๊น์?
- Q78.
- Q79.
- Q80.
- Q81.
- Q82.
- Q83.
- Q84.
- Q85. ์ด๋ค ์ข ๋ฅ์ ์ ๋ณด๊ฐ ์ถ๋ ฅ๋ ๊น์?
- Q86. true๋ฅผ ์ธ์๋ก ์ ๋ฌ ํ ์ ์๋๋ก ์ฃผ์ด์ก์ ๋, hasName์ true๋ก ์ค์ ํ ์ ์๋ ๋ฐฉ๋ฒ์ ์ด๋ ๊ฒ ์ผ๊น์?
- Q87.
- Q88.
- Q89.
- Q90.
- Q91.
- Q92.
- Q93.
- Q94.
- Q95.
- Q96.
- Q97.
- Q98.
- Q99.
- Q100.
- Q101.
- Q102.
- Q103.
- Q104.
- Q105.
- Q106.
- Q107.
- Q108. ๋ค์ ์ค ์๋ณธ ๋ฐฐ์ด์ ์์ ํ๋ method๋ ๋ฌด์์ผ๊น์?
- Q109.
- Q110. ์ด ๋ฉ์๋๋ ๋ฌด์์ ํ ๊น์?
- Q111.
- Q112.
- Q113.
- Q114.
- Q115. ์ด๋ method๊ฐ ๊ฐ 'Hello world!'๋ฅผ ๋ฆฌํด ํ ๊น์?
- Q116.
- Q117. Which of the following options will return 6?
- Q118.
- Q119.
- Q120.
- Q121.
- Q122.
- Q123.
- Q124.
- Q125.
๋ฌธ์ ์ ์ด๋ฆ๊ณผ ํด์ค์ ๋ด ๋ง์๋๋ก ์์ฑํ์๋ค.
- ํด์ฆ ์ถ์ฒ: lydiahallie/javascript-questions
Q1. ๋ณ์ ํธ์ด์คํ ๊ณผ ์ผ์์ ์ฌ๊ฐ์ง๋
function sayHi() {console.log(name);console.log(age);var name = "Lydia";let age = 21;}sayHi();
- ๋ต: undefined, ReferenceError
- ํ์ํ ์ง์: ๋ณ์ ํธ์ด์คํ , var์ letํค์๋๋ก ์ ์ธ๋ ๋ณ์์ ์ด๊ธฐํ ์์ , ์ผ์์ ์ฌ๊ฐ์ง๋(TDZ)
sayHi()
ํจ์ ์คํ๋ณ์
name
์ด ํธ์ด์คํ ๋๋ฉด์ ์ ์ธ, ์ด๊ธฐํ ๋๊ณundefined
ํ ๋นvar
ํค์๋๋ก ์ ์ธ ๋์๊ธฐ ๋๋ฌธ์ ํธ์ด์คํ ์ด ๋ฐ์ํ๋ฉด์ ์ ์ธ๊ณผ ์ด๊ธฐํ๊ฐ ์ด๋ฃจ์ด ์ง๋ค.๋ณ์
age
๊ฐ ํธ์ด์คํ ๋๋ฉด์ ์ ์ธ๋์ง๋ง ์ด๊ธฐํ๋ ์ด๋ฃจ์ด์ง์ง ์๋๋ค.let
ํค์๋๋ก ์ ์ธ ๋ ๋ณ์๋ ํธ์ด์คํ ์ด ์ด๋ฃจ์ด์ง์ง ์์ ๊ฒ ์ฒ๋ผ ๋์ํ๋ค.console.log(name)
์คํ, undefined ์ถ๋ ฅ๋ณ์
name
์ ๊ฐ์ ์์ง ์ด๊ธฐํ๋ง ์ด๋ฃจ์ด ์ก๊ธฐ ๋๋ฌธ์undefined
์ด๋ค.console.log(age)
์คํ, ReferenceError(์ฐธ์กฐ ์๋ฌ) ๋ฐ์๋ณ์
age
๋ ์์ง ์ด๊ธฐํ๊ฐ ์ด๋ฃจ์ด์ง์ง ์์, TDZ์ ์๊ธฐ ๋๋ฌธ์ ์ฐธ์กฐํ ์ ์๋ค.var name = "Lydia"
์คํ๋ณ์
name
์ string ํ์ ์ ๊ฐ"Lydia"
ํ ๋นlet age = 21
์คํ๋ณ์
age
์ด๊ธฐํ, number ํ์ ์ ๊ฐ21
ํ ๋น
sayHi()
ํจ์๊ฐ ์คํ ๋๋ฉด์ var
ํค์๋๋ก ์ ์ธ๋ ๋ณ์ name
์ ํธ์ด์คํ
์ด ๋ฐ์ํ๋ฉด์ ์ด๊ธฐํ ๋จ๊ณ๊ฐ ์คํ ๋๊ณ undefined
๊ฐ์ ๊ฐ์ง ์ํ๊ฐ ๋๋ค. ๋ณ์ age
๋ํ ํธ์ด์คํ
์ ์ํด ์ ์ธ๋์ง๋ง let
ํค์๋๋ก ์ ์ธ๋์๊ธฐ์ ์ด๊ธฐํ ๋จ๊ณ๋ ์ด๋ฃจ์ด์ง์ง ์๋๋ค.
L2, ๋ณ์ name
์ ์ถ๋ ฅ ํ์ง๋ง ๊ฐ์ ์์ง undefined
์ด๋ฏ๋ก undefined๊ฐ ์ถ๋ ฅ ๋๋ค.
L3, ๋ณ์ age
๋ ์์ง ์ด๊ธฐํ ๋จ๊ณ๊ฐ ์ด๋ฃจ์ด์ง์ง ์์ ์ฐธ์กฐํ ์ ์๊ธฐ ๋๋ฌธ์ ReferenceError๊ฐ ๋ฐ์ํ๋ค.
L4, ๋ณ์ name
์ ๋ฌธ์์ด ๊ฐ "Lydia"
๋ฅผ ํ ๋นํ๋ค. L5, ๋ณ์ age
์ด๊ธฐํ๊ฐ ์ด๋ฃจ์ด์ง๊ณ ์ซ์ ๊ฐ 21
์ ํ ๋นํ๋ค.
Q2. var์ let ์ผ๋ก ์ ์ธ๋ ๋ณ์์ ์ค์ฝํ
for (var i = 0; i < 3; i++) {setTimeout(() => console.log(i), 1);}for (let i = 0; i < 3; i++) {setTimeout(() => console.log(i), 1);}
- ๋ต: 3 3 3, 0 1 2
- ํ์ํ ์ง์: var ํค์๋์ let ํค์๋๋ก ์ ์ธ๋ ๋ณ์์ ์ค์ฝํ, ์ด๋ฒคํธ ๋ฃจํ, ํ์คํฌ ํ(์ด๋ฒคํธ ํ)
var
ํค์๋๋ก ์ ์ธ๋ ๋ณ์๋ ํจ์ ๋ ๋ฒจ ์ค์ฝํ ๋ง์ ์ง์ญ ์ค์ฝํ๋ก ์ธ์ ํ๊ณ , let
ํค์๋๋ก ์ ์ธ๋ ๋ณ์๋ ๋ธ๋ก ๋ ๋ฒจ ์ค์ฝํ๋ฅผ ์ง์ญ ์ค์ฝํ๋ก ์ธ์ ํ๋ค.
L1~L3 ์ ์ฒซ ๋ฒ์งธ
for
๋ฌธ(๋ฃจํ) ์คํ๋ณ์
i
์ ์ธ, ์ด๊ธฐํ, number ํ์ ์ ๊ฐ0
ํ ๋น์ด๋
var
ํค์๋๋ก ์ ์ธ ๋ณ์i
๋ ์ ์ญ ๋ณ์๊ฐ ๋๋ค.ํ๊ฐ
i < 3
๋น๊ต (i
: 0),true
์ด๋ฏ๋ก ๋ฐ๋ณต ๋ฌธ ์คํsetTimeout()
ํจ์ ์คํ, WebAPI์ ์์setTimeout()
ํจ์์ ์ฝ๋ฐฑ ํจ์๋ 1ms ํ์ Task Queue๋ก ์ด๋์ฌ๊ธฐ์ ๋งํ๋ ์ฝ๋ฐฑ ํจ์๋
() => console.log(i)
์ด๋ค.
๋ณ์
i
๋++
์ฆ๊ฐ ์ฐ์ฐ์์ ์ํด1
์ด ๋๋ค.ํ๊ฐ
i < 3
๋น๊ต (i
: 1),true
์ด๋ฏ๋ก ๋ฐ๋ณต ๋ฌธ ์คํsetTimeout()
ํจ์ ์คํ, WebAPI์ ์์setTimeout()
ํจ์์ ์ฝ๋ฐฑ ํจ์๋ 1ms ํ์ Task Queue๋ก ์ด๋
๋ณ์
i
๋++
์ฆ๊ฐ ์ฐ์ฐ์์ ์ํด2
๊ฐ ๋๋ค.ํ๊ฐ
i < 3
๋น๊ต (i
: 2),true
์ด๋ฏ๋ก ๋ฐ๋ณต ๋ฌธ ์คํsetTimeout()
ํจ์ ์คํ, WebAPI์ ์์setTimeout()
ํจ์์ ์ฝ๋ฐฑ ํจ์๋ 1ms ํ์ Task Queue๋ก ์ด๋
๋ณ์
i
๋++
์ฆ๊ฐ ์ฐ์ฐ์์ ์ํด3
์ด ๋๋ค.ํ๊ฐ
i < 3
๋น๊ต (i
: 3),false
์ด๋ฏ๋กfor
๋ฌธ ์ข ๋ฃ์ด๋
for
๋ฌธ์ด ์ข ๋ฃ ๋๋ฉด์ Call Stack์ด ๋น์์ง๋ค.Event Loop์ ์ํด Task Queue์ ์๋ ์ฝ๋ฐฑ ํจ์๊ฐ Call Stack์ผ๋ก ์ด๋
์ 4๋ฒ์ ์ฝ๋ฐฑ ํจ์
() => console.log(i)
์คํ,3
์ถ๋ ฅi
๋ ์ ์ญ ๋ณ์์ด๊ณ 11๋ฒ์์i
์ ๊ฐ์3
์ด ๋์๋ค.Event Loop์ ์ํด Task Queue์ ์๋ ์ฝ๋ฐฑ ํจ์๊ฐ Call Stack์ผ๋ก ์ด๋
์ 7๋ฒ์ ์ฝ๋ฐฑ ํจ์
() => console.log(i)
์คํ,3
์ถ๋ ฅEvent Loop์ ์ํด Task Queue์ ์๋ ์ฝ๋ฐฑ ํจ์๊ฐ Call Stack์ผ๋ก ์ด๋
์ 10๋ฒ์ ์ฝ๋ฐฑ ํจ์
() => console.log(i)
์คํ,3
์ถ๋ ฅ
L1~L3 ์ ์ฒซ ๋ฒ์งธ for
๋ฌธ ์คํ, var
ํค์๋๋ก ์ ์ธ๋ ๋ณ์๋ ํจ์ ๋ ๋ฒจ ์ค์ฝํ ๋ง์ ์ง์ญ ์ค์ฝํ๋ก ์ธ์ ํ๊ธฐ ๋๋ฌธ์ ์ ์ญ ๋ณ์๊ฐ ๋๊ณ ๋๋ฌธ์ ๋ฃจํ๊ฐ ์ข
๋ฃ๋๊ณ () => console.log(i)
์ฝ๋ฐฑ ํจ์๊ฐ ์คํ ๋ ๋ ์ ์ญ ๋ณ์์ ์ํฅ์ ๋ฐ์ 3 3 3
์ด ์ถ๋ ฅ๋๋ค.
L5~L7 ์ ๋ ๋ฒ์งธ for
๋ฌธ ๋ํ ์ฒซ ๋ฒ์งธ ๋ฃจํ์ ํฐ ์ฐจ์ด ์์ด ๋์ํ์ง๋ง let
ํค์๋๋ฅผ ์ฌ์ฉํ๊ธฐ ๋๋ฌธ์ ๋ณ์ i
๊ฐ ๋ธ๋ก ๋ ๋ฒจ ์ค์ฝํ๋ฅผ ๊ฐ์ง๋ค๋ ๊ฒ์ด๋ค.
๋ธ๋ก ๋ ๋ฒจ ์ค์ฝํ๋ ํด๋น ๋ธ๋ก ๋ด์์๋ง ์ ํจํ ๊ฒ์ผ๋ก ์ธ์ ํ๊ธฐ ๋๋ฌธ์ ๋ฃจํ๊ฐ ์ข
๋ฃ๋๊ณ () => console.log(i)
์ฝ๋ฐฑ ํจ์๊ฐ ์คํ ๋ ๋ ์ ์ญ ๋ณ์์ ์ํฅ์ ๋ฐ์ง ์์ 0 1 2
๊ฐ ์ถ๋ ฅ๋๋ ๊ฒ์ด๋ค.
for
๋ฌธ์ด ์ข
๋ฃ ๋์์ง๋ง ๊ฐ์ด ์ ์ง ๋ ์ ์๋ ์ด์ ๋ ๋ฐ๋ณต ๋๋ฉด์ ์์ฑ ๋ ๊ฐ๊ฐ์ ๋ ์์ปฌ ํ๊ฒฝ์ด ์ฌ๋ผ์ง์ง ์๊ณ ๋จ์ ์๊ธฐ ๋๋ฌธ์ด๋ค.
p.s - ๋ฌธ์ ์ ์๋ ๋ด์์ ์ต๋ํ ์์ธํ๊ฒ ์์ฑํ๋ ค ํ๋ ์๊ฐ๋ ์ค๋ ๊ฑธ๋ฆฌ๊ณ ๋๋ฌด ๊ณ ํต์ค๋ฝ๋ค. ๐ซ ์ข ๋ ๊ฐ๋จํ๊ฒ ์จ์ผ์ง...
Q3. ํ์ดํ ํจ์์ this
const shape = {radius: 10,diameter() {return this.radius * 2;},perimeter: () => 2 * Math.PI * this.radius};console.log(shape.diameter());console.log(shape.perimeter());
- ๋ต: 20, NaN
- ํ์ํ ์ง์: ํ์ดํ ํจ์์
this
๋ฐ์ธ๋ฉ
L6์ perimeter
๋ฉ์๋๋ ํ์ดํ ํจ์๋ก ์ ์ ๋์๊ธฐ ๋๋ฌธ์ perimeter
์ this
๋ ์์ ์ค์ฝํ์ธ window
๋ฅผ ๊ฐ๋ฅดํจ๋ค. ๋ฐ๋ผ์ undefined
์ด๊ธฐ ๋๋ฌธ์ NaN
๊ฐ ์ถ๋ ฅ๋๋ ๊ฒ์ด๋ค.
TMI -
NaN
๋ 'Not a Number'์ ์ฝ์์ด๊ณ number ํ์ ์ด๋ค.์ซ์๊ฐ ์๋์ง๋ง ์ซ์์ด๋ค ใ ใ ใ ์ใ ใ ใ ใ ใ
ํ์ดํ ํจ์๋ ํจ์ ์์ฒด์ this ๋ฐ์ธ๋ฉ์ด ์๊ณ , ํจ์๊ฐ ์ ์๋ ์์น์ ์์ ์ค์ฝํ์ this
๋ฅผ ์ฐธ์กฐํ๋ค.
'ํ์ดํ ํจ์ ๋ด๋ถ์ this'๋ ํธ์ถํ ๊ฐ์ฒด๋ฅผ ๊ฐ๋ฅดํค์ง ์๊ณ , '์์ ์ค์ฝํ์ this'๋ฅผ ๊ฐ๋ฅดํค๊ธฐ ๋๋ฌธ์ ํ์ดํ ํจ์๋ก ๋ฉ์๋๋ฅผ ์ ์ํ๋ ๊ฒ์ ํผํด์ผ ํ๋ค.
ECMAScript ์คํ์์๋ ES6์ '๋ฉ์๋ ์ถ์ฝ ํํ'์ ์ฌ์ฉํด์ผ ๋ฉ์๋๋ก ์ธ์ ํ๋ค.
Q4. ์๋ฌต์ ํ์ ๋ณํ
+true;!"Lydia";
- ๋ต: 1, false
- ํ์ํ ์ง์: ์๋ฌต์ ํ์ ๋ณํ
L1, +true
๋ +
๋จํญ ์ฐ์ฐ์์ ์ํด number ํ์
์ ๊ฐ 1
๋ก ์๋ฌต์ ํ์
๋ณํ ๋๋ค. ๋ฐ๋๋ก +false
์ผ ๊ฒฝ์ฐ์๋ 0
์ผ๋ก ๋ณํํ๋ค.
+
๋จํญ ์ฐ์ฐ์๋ ํผ์ฐ์ฐ์๊ฐ ์ซ์ ํ์ ์ ๊ฐ์ด ์๋๋ฉด ์ซ์ ํ์ ์ ๊ฐ์ผ๋ก ์๋ฌต์ ํ์ ๋ณํ์ ์ํํ๋ค.
L2, !"Lydia"
๋ !
(๋
ผ๋ฆฌ NOT) ๋จํญ ์ฐ์ฐ์์ ์ํด boolean ํ์
์ ๊ฐ false
๋ก ์๋ฌต์ ํ์
๋ณํ ๋๋ค.
!""
๊ฐ์ด ๋น ๋ฌธ์์ด์ธ ๊ฒฝ์ฐ true
๋ก ๋ณํํ๋ค.
!
์ฐ์ฐ์๋ ์ธ์ ๋ ๋ถ๋ฆฌ์ธ ๊ฐ์ ๋ฐํํ๊ณ , ํผ์ฐ์ฐ์๊ฐ ๋ถ๋ฆฌ์ธ ๊ฐ์ด ์๋๋ฉด ๋ถ๋ฆฌ์ธ ํ์ ์ผ๋ก ์๋ฌต์ ํ์ ๋ณํ๋๋ค.
!
์ฐ์ฐ์๋ ๋จ์ผ ํผ์ฐ์ฐ์๋ฅผtrue
๋ก ๋ณํํ ์ ์์ผ๋ฉดfalse
๋ฅผ ๋ฐํํ๊ณ , ๊ทธ๋ ์ง ์์ผ๋ฉดtrue
๋ฅผ ๋ฐํํ๋ค.๊ฐ๋จํ๊ฒ ๋งํ๋ฉด ํผ์ฐ์ฐ์๊ฐ ํ๊ฐ๋๋ ๋ ผ๋ฆฌ๋ฅผ ๋ฐ์ ์ํจ๋ค.
""
๊ฐ์ด ๋ฌธ์์ด์ด ๋น์ด์๋ ๊ฒฝ์ฐ ์๋ฐ์คํฌ๋ฆฝํธ ์์ง์ Falsy๋ก ๋ณด๋๋ฐ ์ด๊ฒ์ ๊ฑฐ์ง์ผ๋ก ํ๊ฐ๋ ์ ์๋ค๋ ๊ฒ ์ด์ง boolean false
๋์ ๋ค๋ฅด๋ค. "strung"
๊ฐ์ด ๋ฌธ์์ด์ด ๋น์ด์์ง ์๋ค๋ฉด Truthy๋ก ๋ณด๊ณ ์ญ์ true
๋์ ๋ค๋ฅด๋ค.
์ด๋ ๊ฒ '์ฐธ์ด๋ผ๊ณ ๋ณผ ์ ์๋ ๊ฐ(truthy)' ์ด๋ '๊ฑฐ์ง์ด๋ผ๊ณ ๋ณผ ์ ์๋ ๊ฐ(falsy)' ์์ฒด๋ฅผ ์กฐ๊ฑด๋ฌธ์ ์ฌ์ฉํ์ง ๋ง์์ผ ํ๊ณ ๋ฐ๋์ ํ์ ๋ณํ์ ํตํด boolean์ผ๋ก ๋ณํํ์ฌ ์ฌ์ฉํด์ผํ๋ค.
Q5.
const bird = {size: "small"};const mouse = {name: "Mickey",small: true};
- ์ ํ์ง
- A:
mouse.bird.size
๋ ์ ํจํ์ง ์์์ - B:
mouse[bird.size]
๋ ์ ํจํ์ง ์์์ - C:
mouse[bird["size"]]
๋ ์ ํจํ์ง ์์์ - D: ์ด ๋ชจ๋ ๊ฒ๋ค์ ์ ํจํด์.
- A:
- ๋ต: A
- ํ์ํ ์ง์: ๊ฐ์ฒด์ ํค, ๊ฐ์ฒด ์ ํ๊ธฐ๋ฒ ์ ๊ทผ, ๊ฐ์ฒด ๋๊ดํธ ํ๊ธฐ๋ฒ ์ ๊ทผ
Q6.
let c = { greeting: "Hey!" };let d;d = c;c.greeting = "Hello";console.log(d.greeting);
- ์ ํ์ง
- A:
Hello
- B:
Hey!
- C:
undefined
- D:
ReferenceError
- E:
TypeError
- A:
- ๋ต: A
- ํ์ํ ์ง์: pass-by-reference, mutable value
Q7.
let a = 3;let b = new Number(3);let c = 3;console.log(a == b);console.log(a === b);console.log(b === c);
- ์ ํ์ง
- A:
true
false
true
- B:
false
false
true
- C:
true
false
false
- D:
false
true
true
- A:
- ๋ต: C
- ํ์ํ ์ง์: Number ์์ฑ์ ํจ์, ๋๋ฑ ์ฐ์ฐ์(
==
), ์ผ์น ์ฐ์ฐ์(===
)
L2, new Number(3)
๋ 3
์ ํ ๋นํ Number ๋ํผ ๊ฐ์ฒด๋ฅผ ์์ฑํ๋ค. ๋๋ฌธ์ ๋ณ์ b
๋ object ํ์
์ด๋ค.
L5, console.log(a == b)
๋ ๋๋ฑ ์ฐ์ฐ์๋ก ๋น๊ตํ์ฌ ํ์
๊ณผ ๊ด๊ณ์์ด ๊ฐ์ ๋๋ฑ๋ง์ ํ๋ณํ๊ธฐ ๋๋ฌธ์ true
์ด๋ค.
L6, console.log(a === b)
๋ ์ผ์น ์ฐ์ฐ์๋ก ๋น๊ตํ์ฌ ๊ฐ๊ณผ ํ์
์ด ๋ชจ๋ ์ผ์นํด์ผ ํ๊ธฐ ๋๋ฌธ์ false
์ด๋ค. (๋ณ์ a
๋ ์ซ์ ๋ฆฌํฐ๋ด๋ก ์์ฑํ number ํ์
์ ๊ฐ 3
์ด๋ค)
Q8.
class Chameleon {static colorChange(newColor) {this.newColor = newColor;return this.newColor;}constructor({ newColor = "green" } = {}) {this.newColor = newColor;}}const freddie = new Chameleon({ newColor: "purple" });console.log(freddie.colorChange("orange"));
- ์ ํ์ง
- A:
orange
- B:
purple
- C:
green
- D:
TypeError
- A:
- ๋ต: D
- ํ์ํ ์ง์: ํด๋์ค, ์ธ์คํด์ค, ์ ์ ๋ฉ์๋
์ ์ ๋ฉ์๋์ธ colorChange()
๋ ์ธ์คํด์ค freddie
์ ํ๋กํ ํ์
์ฒด์ธ์ ์๋ค.
์ธ์คํด์ค freddie
์ ํ๋กํ ํ์
์ฒด์ธ์ Chameleon
ํด๋์ค๊ฐ ์๊ธฐ ๋๋ฌธ์ colorChange()
๋ฅผ ํธ์ถํ์ง ๋ชปํ๊ณ TypeError
๊ฐ ๋ฐ์ํ๋ ๊ฒ์ด๋ค.
ํด๋์ค๋ก ์์ฑํ ์ธ์คํด์ค์ ํ๋กํ ํ์ ์ฒด์ธ์ ํด๋น ํด๋์ค๋ ์กด์ฌํ์ง ์๊ณ , ํด๋น ํด๋์ค๊ฐ ์์ ํ๊ณ ์๋ ์ ์ ๋ฉ์๋ ๋ํ ์กด์ฌํ ์ ์๊ธฐ ๋๋ฌธ์ ์ธ์คํด์ค์์ ํธ์ถํ ์ ์๋ค.
ํ ๋ง๋๋ก ์ธ์คํด์ค๋ ํด๋์ค์ ์ ์ ๋ฉ์๋๋ฅผ ์์๋ฐ์ ์ ์๋ค.
์ ์ ๋ฉ์๋
ํด๋์ค์์
static
ํค์๋๋ฅผ ์ฌ์ฉํ๋ฉด ์ ์ ๋ฉ์๋๋ฅผ ์ ์ํ ์ ์๊ณ , ํด๋น ํด๋์ค์ ๋ฉ์๋๊ฐ ๋๋ค.
ํด๋์ค๋ ํ๋กํผํฐ/๋ฉ์๋๋ฅผ ๊ฐ์ง ์ ์๋ค.
Class๋ 'ํจ์'๋ก ํ๊ฐ๋๊ณ ํจ์๋ '์ผ๊ธ ๊ฐ์ฒด'์ด๊ธฐ ๋๋ฌธ์ ํ๋กํผํฐ/๋ฉ์๋๋ฅผ ์์ ํ ์ ์๋ค.
Q9.
let greeting; // Typo!greetign = {};console.log(greetign);
- ์ ํ์ง
- A:
{}
- B:
ReferenceError: greetign is not defined
- C:
undefined
- A:
- ๋ต: A
๋ณ์ greetign
์ ํค์๋๋ฅผ ์ฌ์ฉํ์ง ์๊ณ ์ ์ธ ํ์ง ์์๊ธฐ์ var
ํค์๋๋ก ์ ์ธํ ๋ณ์ ์ฒ๋ผ ์ ์ญ ๋ณ์๊ฐ ๋๋ค.
strict ๋ชจ๋๋ฅผ ์ฌ์ฉํ๊ฑฐ๋ ESLint ๊ฐ์ ๋๊ตฌ๋ฅผ ์ฌ์ฉํ๋ฉด ์ด๋ฐ ๋ฌธ์ ๋ฅผ ์๋ฐฉํ ์ ์๋ค.
Q10.
function bark() {console.log("Woof!");}bark.animal = "dog";
- ์ ํ์ง
- A: ๋ณ์ผ ์์ด์, ์ด๊ฑด ์์ ํ ๊ด์ฐฎ์์!
- B:
SyntaxError
์ด ๋ฐฉ๋ฒ์ผ๋ก ํจ์์ ์์ฑ์ ์ถ๊ฐํ ์ ์์ด์. - C:
"Woof"
์ด ์ถ๋ ฅ๋ผ์. - D:
ReferenceError
- ๋ต: A
ํจ์๋ '์ผ๊ธ ๊ฐ์ฒด'์ด๊ธฐ ๋๋ฌธ์ ํ๋กํผํฐ/๋ฉ์๋๋ฅผ ์์ ํ ์ ์๋ค.
Q11.
function Person(firstName, lastName) {this.firstName = firstName;this.lastName = lastName;}const member = new Person("Lydia", "Hallie");Person.getFullName = function() {return `${this.firstName} ${this.lastName}`;};console.log(member.getFullName());
- ์ ํ์ง
- A:
TypeError
- B:
SyntaxError
- C:
Lydia Hallie
- D:
undefined
undefined
- A:
- ๋ต: A
Q12.
function Person(firstName, lastName) {this.firstName = firstName;this.lastName = lastName;}const lydia = new Person("Lydia", "Hallie");const sarah = Person("Sarah", "Smith");console.log(lydia);console.log(sarah);
- ์ ํ์ง
- A:
Person {firstName: "Lydia", lastName: "Hallie"}
๊ทธ๋ฆฌ๊ณundefined
- B:
Person {firstName: "Lydia", lastName: "Hallie"}
๊ทธ๋ฆฌ๊ณPerson {firstName: "Sarah", lastName: "Smith"}
- C:
Person {firstName: "Lydia", lastName: "Hallie"}
๊ทธ๋ฆฌ๊ณ{}
- D:
Person {firstName: "Lydia", lastName: "Hallie"}
๊ทธ๋ฆฌ๊ณReferenceError
- A:
- ๋ต: A
L10, new
ํค์๋๋ฅผ ์ฌ์ฉํ์ง ์์ ์์ฑ์ ํจ์๊ฐ ์๋๋ผ ์ผ๋ฐ ํจ์๋ก ํธ์ถ๋์ด Person
ํจ์ ๋ด๋ถ์ this
๋ ์ ์ญ์ ์ฐธ์กฐํ๊ธฐ ๋๋ฌธ์ undefined
๋ฅผ ๋ฐํํ๋ค.
Q13. ์ด๋ฒคํธ ์ ๋ฌ์ 3๋จ๊ณ๋ ๋ฌด์์ผ๊น์?
- ์ ํ์ง
- A: Target > Capturing > Bubbling
- B: Bubbling > Target > Capturing
- C: Target > Bubbling > Capturing
- D: Capturing > Target > Bubbling
- ๋ต: D
Q14. ๋ชจ๋ ๊ฐ์ฒด๋ ํ๋กํ ํ์ ์ ๊ฐ์ ธ์.
- ์ ํ์ง
- A: true
- B: false
- ๋ต: B
ํ๋กํ ํ์
์ฒด์ธ ์ต์์์๋ ์๋ Object.prototype
๊ฐ์ฒด๋ ํ๋กํ ํ์
์ ๊ฐ์ง๊ณ ์์ง ์๋ค.
Object.prototype
๋ด๋ถ ์ฌ๋กฏ[[Prototype]]
์ ๊ฐ์null
์ด ์ต์์ ๊ฐ์ฒด๋ฅผ ์ ์ธํ ๋ชจ๋ ๊ฐ์ฒด๋ ํ๋กํ ํ์ ์ ๊ฐ์ง๊ณ ์๋ค.
Q15.
function sum(a, b) {return a + b;}sum(1, "2");
- ์ ํ์ง
- A:
NaN
- B:
TypeError
- C:
"12"
- D:
3
- A:
- ๋ต: C
์๋ฌต์ ํ์ ๋ณํ
Q16.
let number = 0;console.log(number++);console.log(++number);console.log(number);
- ์ ํ์ง
- A:
1
1
2
- B:
1
2
2
- C:
0
2
2
- D:
0
1
2
- A:
- ๋ต: C
L2, ์ฆ๊ฐ ์ฐ์ฐ์๊ฐ ์ ๋ฏธ์ ์ฌ์ฉ๋์๊ธฐ ๋๋ฌธ์ 0
์ถ๋ ฅ ์ดํ ๋ณ์ number
์ ๊ฐ์ด 1
์ฆ๊ฐ
L3, ์ฆ๊ฐ ์ฐ์ฐ์๊ฐ ์ ๋์ ์ฌ์ฉ๋์๊ธฐ ๋๋ฌธ์ ๋ณ์ number
์ ๊ฐ์ด 1
์ฆ๊ฐํ์ฌ 2
์ถ๋ ฅ
Q17.
function getPersonInfo(one, two, three) {console.log(one);console.log(two);console.log(three);}const person = "Lydia";const age = 21;getPersonInfo`${person} is ${age} years old`;
- ์ ํ์ง
- A:
"Lydia"
21
["", " is ", " years old"]
- B:
["", " is ", " years old"]
"Lydia"
21
- C:
"Lydia"
["", " is ", " years old"]
21
- A:
- ๋ต: B
์ฒ์๋ณด๋ ๋ฌธ๋ฒ์ด๋ผ ๋นํฉ์ค๋ฝ๋ค ๐ฏ
Tagged templates์ด๋ผ๊ณ ํ๋ค ์์ธํ ๋ด์ฉ์ Template literals - JavaScript | MDN ์ฐธ๊ณ
Q18.
function checkAge(data) {if (data === { age: 18 }) {console.log("You are an adult!");} else if (data == { age: 18 }) {console.log("You are still an adult.");} else {console.log(`Hmm.. You don't have an age I guess`);}}checkAge({ age: 18 });
- ์ ํ์ง
- A:
You are an adult!
- B:
You are still an adult.
- C:
Hmm.. You don't have an age I guess
- A:
- ๋ต: C
Reference Type์ ๊ฐ์ด ์๋๋ผ ์ฐธ์กฐ๊ฐ ๊ฐ์์ผ ํ๋ค. ๋ฐ๋ผ์ C
Q19.
function getAge(...args) {console.log(typeof args);}getAge(21);
- ์ ํ์ง
- A:
"number"
- B:
"array"
- C:
"object"
- D:
"NaN"
- A:
- ๋ต: C
Q20.
function getAge() {"use strict";age = 21;console.log(age);}getAge();
- ์ ํ์ง
- A:
21
- B:
undefined
- C:
ReferenceError
- D:
TypeError
- A:
- ๋ต: C
Q21. sum
์ ๊ฐ์ ๋ฌด์์ผ๊น์?
const sum = eval("10*10+5");
- ์ ํ์ง
- A:
105
- B:
"105"
- C:
TypeError
- D:
"10*10+5"
- A:
- ๋ต: A
Q22. cool_secret์ ๋ช ์๊ฐ์ด๋ ์ ๊ทผ์ด ๊ฐ๋ฅํ ๊น์?
sessionStorage.setItem("cool_secret", 123);
- ์ ํ์ง
- A: ์์ํ, ๋ฐ์ดํฐ๋ ์ฌ๋ผ์ง์ง ์์์.
- B: ์ฌ์ฉ์๊ฐ ํญ์ ๋ซ์ ๋.
- C: ์ฌ์ฉ์๊ฐ ํญ๋ฟ๋ง ์๋๋ผ, ๋ธ๋ผ์ฐ์ ์ ์ฒด๋ฅผ ๋ซ์ ๋.
- D: ์ฌ์ฉ์๊ฐ ์์ ์ ์ปดํจํฐ๋ฅผ ์ข ๋ฃ์์ผฐ์ ๋.
- ๋ต: B
Q23.
var num = 8;var num = 10;console.log(num);
- ์ ํ์ง
- A:
8
- B:
10
- C:
SyntaxError
- D:
ReferenceError
- A:
- ๋ต: B
p.s - ๋ฌธ์ ์ ์์๊ฐ ๋์ด๋์ ๋ฐ๋ผ์ ์๋๊ฑด ์๋๊ฐ๋ณด๋ค
Q24.
const obj = { 1: "a", 2: "b", 3: "c" };const set = new Set([1, 2, 3, 4, 5]);obj.hasOwnProperty("1");obj.hasOwnProperty(1);set.has("1");set.has(1);
- ์ ํ์ง
- A:
false
true
false
true
- B:
false
true
true
true
- C:
true
true
false
true
- D:
true
true
true
true
- A:
- ๋ต: C
L4, ๊ฐ์ฒด์ ํ๋กํผํฐ ํค๋ ๋ฌธ์์ด(ํน์ ์ฌ๋ณผ) ์ด๋ค.
1: "a"
์ 1
์ ์ฌ์ค ์ซ์๋ก ์ด๋ฃจ์ด์ง ๋ฌธ์์ด์ด๊ณ ๋ฐ์ดํ๊ฐ ์๋ต๋์ด ์๋ ๊ฒ์ด๊ธฐ ๋๋ฌธ์ true
L6, ๋ณ์ set
์ ๋ฌธ์์ด ํ์
์ "1"
์ ๊ฐ์ง๊ณ ์์ง ์๊ธฐ ๋๋ฌธ์ ๋น์ฐํ false
Q25.
const obj = { a: "one", b: "two", a: "three" };console.log(obj);
- ์ ํ์ง
- A:
{ a: "one", b: "two" }
- B:
{ b: "two", a: "three" }
- C:
{ a: "three", b: "two" }
- D:
SyntaxError
- A:
- ๋ต: C
a: "one"
์ a: "three"
๋ ๋์ผํ ํค๋ฅผ ์ฌ์ฉํ๊ณ ์๊ธฐ ๋๋ฌธ์ ๋ ๋ค์์๋ a: "three"
๋ก ๋์ฒด๋๋ค.
Q26. JavaScript์ global execution context๋ ๋๊ฐ๋ฅผ ์์ฑํด์. : ์ ์ญ๊ฐ์ฒด์ "this" ํค์๋์์.
- ์ ํ์ง
- A: true
- B: false
- C: ๊ฒฝ์ฐ์ ๋ฐ๋ผ ๋ฌ๋ผ์
- ๋ต: A
๋ฌธ์ ๊ฐ ๋ฌด์จ ๋ป์ธ์ง ์๋ชจ๋ฅด๊ฒ ๋ค.
(๋์ํ๊ฒฝ์ ๋ฐ๋ผ์) ์ ์ญ๊ฐ์ฒด๋ฅผ ์์ฑํ๊ณ ์ ์ญ๊ฐ์ฒด์ this๋ฅผ ๋ฐ์ธ๋ฉํ๋ ๊ฑธ ์ง๋ฌธํ๋๊ฑด๊ฐ..
p.s - ๊ณง globalThis๋ก ํธํ๊ฒ ๊ตฌ๋ถํ๋ ๋ ์ด ์จ๋ค. (github.com/tc39/pro...l-global)
Q27.
for (let i = 1; i < 5; i++) {if (i === 3) continue;console.log(i);}
- ์ ํ์ง
- A:
1
2
- B:
1
2
3
- C:
1
2
4
- D:
1
3
4
- A:
- ๋ต: C
Q28.
String.prototype.giveLydiaPizza = () => {return "Just give Lydia pizza already!";};const name = "Lydia";name.giveLydiaPizza();
- ์ ํ์ง
- A:
"Just give Lydia pizza already!"
- B:
TypeError: not a function
- C:
SyntaxError
- D:
undefined
- A:
- ๋ต: A
Q29.
const a = {};const b = { key: "b" };const c = { key: "c" };a[b] = 123;a[c] = 456;console.log(a[b]);
- ์ ํ์ง
- A:
123
- B:
456
- C:
undefined
- D:
ReferenceError
- A:
- ๋ต: B
a["[object Object]"]
Q30.
const foo = () => console.log("First");const bar = () => setTimeout(() => console.log("Second"));const baz = () => console.log("Third");bar();foo();baz();
- ์ ํ์ง
- A:
First
Second
Third
- B:
First
Third
Second
- C:
Second
First
Third
- D:
Second
Third
First
- A:
- ๋ต: B
Q31. ๋ฒํผ์ ํด๋ฆญํ์๋ event.target์ ๋ฌด์์ผ๊น์?
<div onclick="console.log('first div')"><div onclick="console.log('second div')"><button onclick="console.log('button')">Click!</button></div></div>
- ์ ํ์ง
- A: ์ธ๋ถ์
div
- B: ๋ด๋ถ์
div
- C:
button
- D: ์ค์ฒฉ๋ ๋ชจ๋ ์์์ ๋ฐฐ์ด
- A: ์ธ๋ถ์
- ๋ต: C
Q32. p ํ๊ทธ๋ฅผ ํด๋ฆญํ๋ฉด ๋ก๊ทธ์ ์ถ๋ ฅ์ ๋ฌด์์ผ๊น์?
<div onclick="console.log('div')"><p onclick="console.log('p')">Click here!</p></div>
- ์ ํ์ง
- A:
p
div
- B:
div
p
- C:
p
- D:
div
- A:
- ๋ต: A
target์ธ <p>
ํ๊ทธ์์ ๋ถํฐ ๋ฒ๋ธ๋ง ๋๋ฉด์ ์ด๋ฒคํธ ํธ๋ค๋ฌ๊ฐ ๋์ํ๋ค.
Q33.
const person = { name: "Lydia" };function sayHi(age) {console.log(`${this.name} is ${age}`);}sayHi.call(person, 21);sayHi.bind(person, 21);
- ์ ํ์ง
- A:
undefined is 21
Lydia is 21
- B:
function
function
- C:
Lydia is 21
Lydia is 21
- D:
Lydia is 21
function
- A:
- ๋ต: D
Function.prototype.call()
๋ฉ์๋๋ ํจ์์ ์ธ์๋ฅผ ์ ๋ฌํด this์ ๋ฐ์ธ๋ฉํ๊ณ ํธ์ถ(์คํ)ํ๋ค.
call()
์ ์ ์ฌ ๋ฐฐ์ด ๊ฐ์ฒด์ ๋ฐฐ์ด ๋ฉ์๋(๊ณ ์ฐจ ํจ์)๋ฅผ ์ฌ์ฉํ๋ ค๊ณ ํ ๋ ์ ์ฉํ๋ค.
Function.prototype.bind()
call๊ณผ ๋ง์ฐฌ๊ฐ์ง๋ก ์ธ์๋ฅผ ์ ๋ฌํด this์ ๋ฐ์ธ๋ฉ ํ์ง๋ง ํธ์ถ์ ํ์ง ์๊ณ ํด๋น ํจ์์ ๋ณต์ฌ๋ณธ์ ๋ฆฌํดํ๋ค.
bind()
๋ ๋ฉ์๋์ this ์ ๋ฉ์๋ ๋ด๋ถ์ ์ค์ฒฉ ํจ์์ this ๋ฅผ ์ผ์น์์ผ์ค ๋ ์ ์ฉํ๋ค.
Q34.
function sayHi() {return (() => 0)();}console.log(typeof sayHi());
- ์ ํ์ง
- A:
"object"
- B:
"number"
- C:
"function"
- D:
"undefined"
- A:
- ๋ต: B
ํจ์ sayHi()
๋ ์ฆ์ ์คํ ํจ์๋ฅผ ๋ฐํํ๊ณ ์ด ์ฆ์ ์คํ ํจ์๋ ์ซ์ ํ์
์ ๊ฐ 0
์ ๋ฐํํ๋ค.
Q35. ์ด ๊ฐ๋ค ์ค ์ด๋ ๊ฒ์ด ๊ฑฐ์ง ๊ฐ์ ๊ฐ ์ผ๊น์?
0;new Number(0);("");(" ");new Boolean(false);undefined;
- ์ ํ์ง
- A:
0
,''
,undefined
- B:
0
,new Number(0)
,''
,new Boolean(false)
,undefined
- C:
0
,''
,new Boolean(false)
,undefined
- D: ๋ชจ๋ ๊ฐ์ ๊ฑฐ์ง
- A:
- ๋ต: A
Q36.
console.log(typeof typeof 1);
- ์ ํ์ง
- A:
"number"
- B:
"string"
- C:
"object"
- D:
"undefined"
- A:
- ๋ต: B
p.s - ๐ฎ... ์์๋ ๋ชปํ ๋ฌธ์ ใด(ยฐ0ยฐ)ใฑ
Q37.
const numbers = [1, 2, 3];numbers[10] = 11;console.log(numbers);
- ์ ํ์ง
- A:
[1, 2, 3, 7 x null, 11]
- B:
[1, 2, 3, 11]
- C:
[1, 2, 3, 7 x empty, 11]
- D:
SyntaxError
- A:
- ๋ต: C
์คํ ํ๊ฒฝ์ ๋ฐ๋ผ ๋ค๋ฅด๊ฒ ๋์ด
numbers[3]
๋ถํฐ numbers[9]
์ ๊ฐ์ undefined
Q38.
(() => {let x, y;try {throw new Error();} catch (x) {(x = 1), (y = 2);console.log(x);}console.log(x);console.log(y);})();
- ์ ํ์ง
- A:
1
undefined
2
- B:
undefined
undefined
undefined
- C:
1
1
2
- D:
1
undefined
undefined
- A:
- ๋ต: A
Q39. JavaScript์ ๋ชจ๋ ๊ฒ์...
- ์ ํ์ง
- A: primitive ๋๋ object
- B: function ๋๋ object
- C: ํจ์ ๋ฌธ์ ! objects๋ง
- D: number ๋๋ object
- ๋ต: A
Q40.
[[0, 1], [2, 3]].reduce((acc, cur) => {return acc.concat(cur);},[1, 2]);
- ์ ํ์ง
- A:
[0, 1, 2, 3, 1, 2]
- B:
[6, 1, 2]
- C:
[1, 2, 0, 1, 2, 3]
- D:
[1, 2, 6]
- A:
- ๋ต: C
์ด๊ธฐ๊ฐ [1, 2]
๋ฅผ ๊ฐ์ง๊ณ ์คํ๋๋ค.
Q41.
!!null;!!"";!!1;
- ์ ํ์ง
- A:
false
true
false
- B:
false
false
true
- C:
false
true
true
- D:
true
true
false
- A:
- ๋ต: B
null
, ""
์ Falsy
1
์ Truthy
Q42. setInterval
๋ฉ์๋๋ ๋ธ๋ผ์ฐ์ ์๊ฒ ๋ฌด์์ ๋ฆฌํด ํ ๊น์?
setInterval(() => console.log("Hi"), 1000);
- ์ ํ์ง
- A: ์ ๋ํฌํ id
- B: ์ง์ ๋ ๋ฐ๋ฆฌ์ด
- C: ํต๊ณผ๋ ํจ์
- D:
undefined
- ๋ต: A
์ซ์๋ก ์ด๋ฃจ์ด์ง intervalID
๋ฅผ ๋ฐํํ๋ค.
setInterval()
๊ณผsetTimeout()
์ ID๋ฅผ ๊ณต์ ํ๋ค.
Q43.
[..."Lydia"];
- ์ ํ์ง
- A:
["L", "y", "d", "i", "a"]
- B:
["Lydia"]
- C:
[[], "Lydia"]
- D:
[["L", "y", "d", "i", "a"]]
- A:
- ๋ต: A
Q44.
function* generator(i) {yield i;yield i * 2;}const gen = generator(10);console.log(gen.next().value);console.log(gen.next().value);
- ์ ํ์ง
- A:
[0, 10], [10, 20]
- B:
20, 20
- C:
10, 20
- D:
0, 10
๊ทธ๋ฆฌ๊ณ10, 20
- A:
- ๋ต: C
์ ๋๋ ์ดํฐ ํจ์๋
yield
ํค์๋๋ฅผ ๋ง๋๋ฉด ์คํ์ ์ค๋จํ๊ณ ๋ค์ ์๋ ๊ฐ์ ๋ฐํํ๋ค.
L6, ์ ๋๋ ์ดํฐ ๊ฐ์ฒด ์์ฑํ๊ณ i
๋ฅผ ์ซ์ ๊ฐ 10
์ผ๋ก ์ด๊ธฐํ
L8, next()
๋ฉ์๋๊ฐ ์คํ๋๊ณ yield i
๋ฅผ ๋ง๋์ 10
์ ์ถ๋ ฅ
L9, ๋ค์ํ๋ฒ next()
๋ฉ์๋๊ฐ ์คํ๋๊ณ yield i * 2
๋ฅผ ๋ง๋์ 20
์ ์ถ๋ ฅ
Q45.
const firstPromise = new Promise((res, rej) => {setTimeout(res, 500, "one");});const secondPromise = new Promise((res, rej) => {setTimeout(res, 100, "two");});Promise.race([firstPromise, secondPromise]).then(res => console.log(res));
- ์ ํ์ง
- A:
"one"
- B:
"two"
- C:
"two" "one"
- D:
"one" "two"
- A:
- ๋ต: B
Promise.race()
๋ ๊ฐ์ฅ ๋จผ์ ์ฒ๋ฆฌ๋ ํ๋ก๋ฏธ์ค๊ฐ resolveํ ์ฒ๋ฆฌ ๊ฒฐ๊ณผ๋ฅผ resolveํ๋ ์๋ก์ด ํ๋ก๋ฏธ์ค๋ฅผ ๋ฐํํ๊ธฐ ๋๋ฌธ์ secondPromise
์ two
๊ฐ ์ถ๋ ฅ๋๋ค.
Q46.
let person = { name: "Lydia" };const members = [person];person = null;console.log(members);
- ์ ํ์ง
- A:
null
- B:
[null]
- C:
[{}]
- D:
[{ name: "Lydia" }]
- A:
- ๋ต: D
L2, ๋ณ์ members
์ ๊ฐ์ [{ name: "Lydia" }]
์ด ๋๊ณ members[0]
๊ณผ ๋ณ์ person
์ ๊ฐ์ ๊ฐ์ฒด๋ฅผ ์ฐธ์กฐํ๊ณ ์๋ค.
L3, ๋ณ์ person
์ ๊ฐ์ null
๋ก ๋ณ๊ฒฝํ์ฌ๋ members[0]
์ ์ฐธ์กฐ๋ ๋ฐ๋์ง ์๊ธฐ ๋๋ฌธ์ ๊ทธ๋๋ก ๋จ๊ฒ๋๋ค.
Q47.
const person = {name: "Lydia",age: 21};for (const item in person) {console.log(item);}
- ์ ํ์ง
- A:
{ name: "Lydia" }, { age: 21 }
- B:
"name", "age"
- C:
"Lydia", 21
- D:
["name", "Lydia"], ["age", 21]
- A:
- ๋ต: B
๊ฐ์ฒด์ ํค๋ฅผ ์ถ๋ ฅํ๋ค. ๊ฐ์ ์ถ๋ ฅํ๊ณ ์ถ๋ค๋ฉด ์๋์ ๊ฐ์ด ํ๋ฉด ๋๋ค.
const person = {name: "Lydia",age: 21};for (const item in person) {console.log(person[item]);}
Q48.
console.log(3 + 4 + "5");
- ์ ํ์ง
- A:
"345"
- B:
"75"
- C:
12
- D:
"12"
- A:
- ๋ต: B
Q49. num
์ ๊ฐ์ ๋ฌด์์ผ๊น์?
const num = parseInt("7*6", 10);
- ์ ํ์ง
- A:
42
- B:
"42"
- C:
7
- D:
NaN
- A:
- ๋ต: C
๋ฌธ์์ด์์ ์ฒซ ๋ฒ์งธ 10์ง์์ธ 7
์ ๋ณ์ num
์ ํ ๋นํ๋ค.
parseInt()
๋ ์ฒซ ๋ฒ์งธ ๋ฌธ์์ด์ ์ซ์๋ก ๋ณํํ ์ ์๋ ๊ฒฝ์ฐNaN
๋ฅผ ๋ฐํํ๋ค
Q50.
[1, 2, 3].map(num => {if (typeof num === "number") return;return num * 2;});
- ์ ํ์ง
- A:
[]
- B:
[null, null, null]
- C:
[undefined, undefined, undefined]
- D:
[ 3 x empty ]
- A:
- ๋ต: C
๊ฐ์ฒด ๋ด๋ถ์ [1, 2, 3]
์ ๋ชจ๋ ์ซ์์ด๊ธฐ ๋๋ฌธ์ L2์ if๋ฌธ์ด ์คํ๋์ด ์๋ฌต์ ์ผ๋ก undefined
๋ฅผ ๋ฐํํ๋ค.
Q51.
function getInfo(member, year) {member.name = "Lydia";year = "1998";}const person = { name: "Sarah" };const birthYear = "1997";getInfo(person, birthYear);console.log(person, birthYear);
- ์ ํ์ง
- A:
{ name: "Lydia" }, "1997"
- B:
{ name: "Sarah" }, "1998"
- C:
{ name: "Lydia" }, "1998"
- D:
{ name: "Sarah" }, "1997"
- A:
- ๋ต: A
๋ณ์ birthYear
๋ ์์ํ ํ์
(Primitive Type)์ธ ๋ฌธ์์ด "1997"
์ด๋ค.
์์ํ์ pass-by-value์ด๊ธฐ ๋๋ฌธ์ ํจ์ getInfo()
์ ์ธ์ year
๋ก ์ฌ์ฉ๋ ๋ ๊ฐ์ด ๋ณต์ฌ๋์ด ์ ๋ฌ๋๋ค. ๋ฐ๋ผ์ birthYear
์ year
๋ ๊ฐ์ ๋ฌธ์์ด ํ์
์ ๊ฐ "1997"
์ ๊ฐ์ง๊ณ ์์ ๋ฟ ์๋ก ๋ค๋ฅธ ์ฐธ์กฐ๋ฅผ ๊ฐ์ง๊ณ ์๊ธฐ ๋๋ฌธ์ ํจ์ getInfo()
๋ด๋ถ, L3์์ year = "1998"
๋ก ๊ฐ์ ๋ณ๊ฒฝํด๋ ๋ณ์ birthYear
์ ๋ ์ํฅ์ด ์๋ค.
๋ณ์ person
์ ๊ฐ์ฒด ํ์
(Object Type)์ด๋ค.
๊ฐ์ฒด ํ์
์ pass-by-reference์ด๊ธฐ ๋๋ฌธ์ ํจ์ getInfo()
์ ์ธ์ member
๋ก ์ฌ์ฉ๋ ๋ (๋ฉ๋ชจ๋ฆฌ์) ์ฐธ์กฐ ๊ฐ์ ๋ณต์ฌํด์ ์ ๋ฌํ๋ค. ๋ฐ๋ผ์ person
๊ณผ member
๋ ๊ฐ์ ๊ณณ์ ์ฐธ์กฐํ๊ณ ์๊ธฐ ๋๋ฌธ์ ํจ์ getInfo()
๋ด๋ถ, L2์์ member.name = "Lydia"
๋ก ๊ฐ์ ๋ณ๊ฒฝํ๋ฉด ๋ณ์ person
๋ ์ํฅ์ ๋ฐ์ ๊ฐ์ด ๋ณ๊ฒฝ๋๋ค.
๋ณ์
person
์ด const ํค์๋๋ฅผ ์ฌ์ฉํด ์ ์ธ๋์๋ค ํด๋ ๊ฐ์ ๊ฐ์ฒด๋ก ๊ฐ์ง๊ณ ์๊ธฐ ๋๋ฌธ์ ์ฌํ ๋น๊ณผ ๊ฐ์ ์๋ณ์๋ฅผ ๊ฐ์ง๋ ๋ณ์๋ฅผ ์ ์ธํ ์ ์๊ฒ ๋ง์ ์ ์์ ๋ฟ, ๊ฐ์ผ๋ก ๊ฐ์ง๊ณ ์๋ ๊ฐ์ฒด์ ๋ณ๊ฒฝ์ ๋ง์์ ์๋ค. ๊ฐ์ฒด ํ์ ์ ๋ถ๋ณ์ฑ์ ๋ณด์ฅํ์ง ์๋๋ค.๋ถ๋ณ์ฑ์ ๋ณด์ฅํ๊ธฐ ์ํด ๊ฐ์ฒด ํ์ ์ ๊ฐ์ ๋ณต์ฌํ์ฌ ๋ค๋ฃจ์ด์ผ ํ๋ค.
Q52.
function greeting() {throw "Hello world!";}function sayHi() {try {const data = greeting();console.log("It worked!", data);} catch (e) {console.log("Oh no an error:", e);}}sayHi();
- ์ ํ์ง
- A:
"It worked! Hello world!"
- B:
"Oh no an error: undefined"
- C:
SyntaxError: can only throw Error objects
- D:
"Oh no an error: Hello world!"
- A:
- ๋ต: D
Q53.
function Car() {this.make = "Lamborghini";return { make: "Maserati" };}const myCar = new Car();console.log(myCar.make);
- ์ ํ์ง
- A:
"Lamborghini"
- B:
"Maserati"
- C:
ReferenceError
- D:
TypeError
- A:
- ๋ต: B
Q54.
(() => {let x = (y = 10);})();console.log(typeof x);console.log(typeof y);
- ์ ํ์ง
- A:
"undefined", "number"
- B:
"number", "number"
- C:
"object", "number"
- D:
"number", "undefined"
- A:
- ๋ต: A
Q55.
class Dog {constructor(name) {this.name = name;}}Dog.prototype.bark = function() {console.log(`Woof I am ${this.name}`);};const pet = new Dog("Mara");pet.bark();delete Dog.prototype.bark;pet.bark();
- ์ ํ์ง
- A:
"Woof I am Mara"
,TypeError
- B:
"Woof I am Mara"
,"Woof I am Mara"
- C:
"Woof I am Mara"
,undefined
- D:
TypeError
,TypeError
- A:
- ๋ต: A
Q56.
const set = new Set([1, 1, 2, 3, 4]);console.log(set);
- ์ ํ์ง
- A:
[1, 1, 2, 3, 4]
- B:
[1, 2, 3, 4]
- C:
{1, 1, 2, 3, 4}
- D:
{1, 2, 3, 4}
- A:
- ๋ต: D
Q57.
// counter.jslet counter = 10;export default counter;
// index.jsimport myCounter from "./counter";myCounter += 1;console.log(myCounter);
- ์ ํ์ง
- A:
10
- B:
11
- C:
Error
- D:
NaN
- A:
- ๋ต: C
import
๋ ๋ชจ๋์ read-only
Q58.
const name = "Lydia";age = 21;console.log(delete name);console.log(delete age);
- ์ ํ์ง
- A:
false
,true
- B:
"Lydia"
,21
- C:
true
,true
- D:
undefined
,undefined
- A:
- ๋ต: A
delete
์ฐ์ฐ์๋ ๊ฐ์ฒด์ ํ๋กํผํฐ๋ฅผ ์ญ์ ํ๊ณ ์ฑ๊ณตํ๋ฉด true
๋ฅผ ๋ฐํํ๋ค.
L2, age
๋ ์ ์ญ ๊ฐ์ฒด์ ํ๋กํผํฐ ์์ผ๋ก ์ญ์ ๊ฐ ๊ฐ๋ฅํ๋ค.
Q59.
const numbers = [1, 2, 3, 4, 5];const [y] = numbers;console.log(y);
- ์ ํ์ง
- A:
[[1, 2, 3, 4, 5]]
- B:
[1, 2, 3, 4, 5]
- C:
1
- D:
[1]
- A:
- ๋ต: C
numbers
์ ์ฒซ ๋ฒ์งธ ์์์ธ 1
์ y
์ ๊ตฌ์กฐ ๋ถํด ํ ๋นํ๋ค.
Q60.
const user = { name: "Lydia", age: 21 };const admin = { admin: true, ...user };console.log(admin);
- ์ ํ์ง
- A:
{ admin: true, user: { name: "Lydia", age: 21 } }
- B:
{ admin: true, name: "Lydia", age: 21 }
- C:
{ admin: true, user: ["Lydia", 21] }
- D:
{ admin: true }
- A:
- ๋ต: B
Q61.
const person = { name: "Lydia" };Object.defineProperty(person, "age", { value: 21 });console.log(person);console.log(Object.keys(person));
- ์ ํ์ง
- A:
{ name: "Lydia", age: 21 }
,["name", "age"]
- B:
{ name: "Lydia", age: 21 }
,["name"]
- C:
{ name: "Lydia"}
,["name", "age"]
- D:
{ name: "Lydia"}
,["age"]
- A:
- ๋ต: B
Object.defineProperty()
๋ ๊ฐ์ฒด์ ํ๋กํผํฐ๋ฅผ ์ถ๊ฐํ๊ฑฐ๋ ์์ ํ ์ ์๋ค.
defineProperty()
๋ฉ์๋๋ฅผ ์ฌ์ฉํด ์ถ๊ฐํ ํ๋กํผํฐ๋ ๊ธฐ๋ณธ์ ์ผ๋ก ๋ถ๋ณํ๊ณ ์ด๊ฑฐ์ ์์ ์ด ๋ถ๊ฐ๋ฅํ๋ค.
์ผ๋ฐ์ ์ธ ํ๋กํผํฐ ํ ๋น์ ํตํด ์ถ๊ฐํ๋ฉด ์ด๊ฑฐ์ ์์ ์ด ๊ฐ๋ฅํ๋ค.
Q62.
const settings = {username: "lydiahallie",level: 19,health: 90};const data = JSON.stringify(settings, ["level", "health"]);console.log(data);
- ์ ํ์ง
- A:
"{"level":19, "health":90}"
- B:
"{"username": "lydiahallie"}"
- C:
"["level", "health"]"
- D:
"{"username": "lydiahallie", "level":19, "health":90}"
- A:
- ๋ต: A
์ฐธ์กฐ: JSON.stringify() - JavaScript | MDN
Q63.
let num = 10;const increaseNumber = () => num++;const increasePassedNumber = number => number++;const num1 = increaseNumber();const num2 = increasePassedNumber(num1);console.log(num1);console.log(num2);
- ์ ํ์ง
- A:
10
,10
- B:
10
,11
- C:
11
,11
- D:
11
,12
- A:
- ๋ต: A
Q16๊ณผ ์ ์ฌํ ๋ฌธ์
L6, ๋ฐํ ํ์ ๊ฐ์ด ์ฆ๊ฐํ๊ธฐ ๋๋ฌธ์ ๋ณ์ num1
์ ์ซ์ ๊ฐ 10
์ด๋ค.
ํจ์
increaseNumber()
๋num
์ ์ซ์ ๊ฐ10
์ ๋ฐํํ๊ณ ์ ๋ฏธ์ ์ฌ์ฉ๋ ์ฆ๊ฐ ์ฐ์ฐ์๊ฐ ๊ฐ์ ์ฆ๊ฐ์์ผ11
๋๋ค.
L7, ์์ ์ ์ฌํ๋ค. ํจ์ increasePassedNumber()
์ ํ๋ผ๋ฏธํฐ number
์ ๋ณ์ num1
์ ๊ฐ 10
์ ์ ๋ฌํด์ ์ฌ์ฉํ๋ค.
ํจ์
increaseNumber()
๋ L1์์ ์ ์ธ๋ ๋ณ์num
์ ๊ฐ์ ๋ณํ ์ํค์ง๋ง ํจ์increasePassedNumber()
๋ ๋ณ์num
์ ์ํฅ์ ์ฃผ์ง ์๋๋ค.
Q64.
const value = { number: 10 };const multiply = (x = { ...value }) => {console.log(x.number *= 2);};multiply();multiply();multiply(value);multiply(value);
- ์ ํ์ง
- A:
20
,40
,80
,160
- B:
20
,40
,20
,40
- C:
20
,20
,20
,40
- D:
NaN
,NaN
,20
,40
- A:
- ๋ต: C
ํจ์ multiply
์ ํ๋ผ๋ฏธํฐ x
๋ ๊ธฐ๋ณธ ๊ฐ์ผ๋ก ๋ณ์ value
๋ฅผ ์คํ๋ ๋ ์ฐ์ฐ์๋ก ๋ณต์ฌํด์ ์ฌ์ฉํ๊ณ ์๊ธฐ ๋๋ฌธ์ ๋ณ์ value
๊ฐ ๊ฐ๋ฅดํค๋ ๊ฐ์ฒด์ ์ํฅ์ ์ฃผ์ง ์๋๋ค.
L9, L10, multiply(value)
๋ ๋ณ์ value
๊ฐ ๊ฐ๋ฅดํค๋ ๊ฐ์ฒด๋ฅผ ์ ๋ฌ๋ฐ์ ์์ ํ๊ธฐ ๋๋ฌธ์ ๊ฐ์ด ์ฆ๊ฐํ๋ค.
Q65.
[1, 2, 3, 4].reduce((x, y) => console.log(x, y));
- ์ ํ์ง
- A:
1
2
๊ทธ๋ฆฌ๊ณ3
3
๊ทธ๋ฆฌ๊ณ6
4
- B:
1
2
๊ทธ๋ฆฌ๊ณ2
3
๊ทธ๋ฆฌ๊ณ3
4
- C:
1
undefined
๊ทธ๋ฆฌ๊ณ2
undefined
๊ทธ๋ฆฌ๊ณ3
undefined
๊ทธ๋ฆฌ๊ณ4
undefined
- D:
1
2
๊ทธ๋ฆฌ๊ณundefined
3
๊ทธ๋ฆฌ๊ณundefined
4
- A:
- ๋ต: D
Q50๊ณผ ์ ์ฌ
์ฝ๋ฐฑ ํจ์๊ฐ ๊ฐ์ ๋ฆฌํดํ์ง ์๊ธฐ ๋๋ฌธ์ ํ์ฌ ๊ฐ๋ง ์ถ๋ ฅํ๋ค.
์ฒ์ ์ถ๋ ฅ์์ x
๊ฐ 1
์ธ ์ด์ ๋ ๋ฐฐ์ด์ ์ฒซ ๋ฒ์งธ ๊ฐ์ ์ด๊ธฐ๊ฐ์ผ๋ก ์ฌ์ฉํ๊ธฐ ๋๋ฌธ์ด๋ค.
Q66. Dog
ํด๋์ค๋ฅผ ์ฑ๊ณต์ ์ผ๋ก ํ์ฅํ ์ ์๋ ์์ฑ์๋ ์ด๋ ๊ฒ์ผ๊น์?
class Dog {constructor(name) {this.name = name;}};class Labrador extends Dog {// 1constructor(name, size) {this.size = size;}// 2constructor(name, size) {super(name);this.size = size;}// 3constructor(size) {super(name);this.size = size;}// 4constructor(name, size) {this.name = name;this.size = size;}};
- ์ ํ์ง
- A: 1
- B: 2
- C: 3
- D: 4
- ๋ต: B
Q67.
// index.jsconsole.log('running index.js');import { sum } from './sum.js';console.log(sum(1, 2));// sum.jsconsole.log('running sum.js');export const sum = (a, b) => a + b;
- ์ ํ์ง
- A:
running index.js
,running sum.js
,3
- B:
running sum.js
,running index.js
,3
- C:
running sum.js
,3
,running index.js
- D:
running index.js
,undefined
,running sum.js
- A:
- ๋ต: B
์ฐธ๊ณ : github.com/lydiahal...sues/218
Q68.
console.log(Number(2) === Number(2))console.log(Boolean(false) === Boolean(false))console.log(Symbol('foo') === Symbol('foo'))
- ์ ํ์ง
- A:
true
,true
,false
- B:
false
,true
,false
- C:
true
,false
,true
- D:
true
,true
,true
- A:
- ๋ต: A
symbol์ ํญ์ ๊ณ ์ ํ๋ค.
์ฐธ๊ณ : developer.mozilla.org/ko...bol
Q69.
const name = "Lydia Hallie"console.log(name.padStart(13))console.log(name.padStart(2))
- ์ ํ์ง
- A:
"Lydia Hallie"
,"Lydia Hallie"
- B:
" Lydia Hallie"
," Lydia Hallie"
("[13x whitespace]Lydia Hallie"
,"[2x whitespace]Lydia Hallie"
) - C:
" Lydia Hallie"
,"Lydia Hallie"
("[1x whitespace]Lydia Hallie"
,"Lydia Hallie"
) - D:
"Lydia Hallie"
,"Lyd"
- A:
- ๋ต: C
์ฐธ๊ณ : String.prototype.padStart() - JavaScript | MDN , tc39/proposal-string-pad-start-end
Q70.
console.log("๐ฅ" + "๐ป");
- ์ ํ์ง
- A:
"๐ฅ๐ป"
- B:
257548
- C: ํด๋น ์ฝ๋ ์ฃผ์๋ฅผ ํฌํจํ๋ ๋ฌธ์์ด
- D: ์๋ฌ
- A:
- ๋ต: A
...?
Q71. console.log ํํ์ ๋ค์ ์ธ๊ธ๋ ๊ฐ์ ์ด๋ป๊ฒ ์ถ๋ ฅํ ์ ์์๊น์?
function* startGame() {const answer = yield "Do you love JavaScript?";if (answer !== "Yes") {return "Oh wow... Guess we're gone here";}return "JavaScript loves you back โค๏ธ";}const game = startGame();console.log(/* 1 */); // Do you love JavaScript?console.log(/* 2 */); // JavaScript loves you back โค๏ธ
- ์ ํ์ง
- A:
game.next("Yes").value
๊ทธ๋ฆฌ๊ณgame.next().value
- B:
game.next.value("Yes")
๊ทธ๋ฆฌ๊ณgame.next.value()
- C:
game.next().value
๊ทธ๋ฆฌ๊ณgame.next("Yes").value
- D:
game.next.value()
๊ทธ๋ฆฌ๊ณgame.next.value("Yes")
- A:
- ๋ต: C
Q72.
console.log(String.raw`Hello\nworld`);
- ์ ํ์ง
- A:
Hello world!
- B:
Hello
world
- C:
Hello\nworld
- D:
Hello\n
world
- A:
- ๋ต: C
String.raw
๋ฉ์๋๋ ์ด์ค์ผ์ด์ค ๋ฌธ์๋ฅผ ๋ฌด์ํ๋ค.
์ฐธ๊ณ : String.raw() - JavaScript | MDN
Q73.
async function getData() {return await Promise.resolve("I made it!");}const data = getData();console.log(data);
- ์ ํ์ง
- A:
"I made it!"
- B:
Promise {<resolved>: "I made it!"}
- C:
Promise {<pending>}
- D:
undefined
- A:
- ๋ต: C
Q74.
function addToList(item, list) {return list.push(item);}const result = addToList("apple", ["banana"]);console.log(result);
- ์ ํ์ง
- A:
['banana', 'apple']
- B:
2
- C:
true
- D:
undefined
- A:
- ๋ต: B
Array.prototype.push()
๋ ๋ฐฐ์ด์ ๋์ ์์๋ฅผ ์ถ๊ฐํ ํ ๋ฐฐ์ด์ ๊ธธ์ด๋ฅผ ๋ฐํํ๊ธฐ ๋๋ฌธ์ 2
๋ฌธ์ ์๋ณธ์ ํด์ค์ '์๋ก์ด ๋ฐฐ์ด์ ๊ธธ์ด๋ฅผ ๋ฆฌํดํด์!' ๋ผ๊ณ ์ค๋ช ์ด ๋์ด์๋๋ฐ ์๋ก์ด ๋ฐฐ์ด์ ๋ฐํํ๋ค๊ณ ์คํดํ๊ธฐ ์ฌ์ด ๋ฌธ์ฅ์ธ ๊ฒ ๊ฐ๋ค.
push()
pop()
unshift()
shift()
์ด ๋ฉ์๋๋ค์ ์๋ก์ด ๋ฐฐ์ด์ ๋ฐํํ์ง ์๊ณ ๋ชจ๋ ์๋ณธ ๋ฐฐ์ด์ ์์ ํ๋ค.p.s - ์ ๊ณ ๋ณด๋ ๋ฐ์ ์ถ๊ฐ์ ์ผ๋ก ์ค๋ช ์ด ์์๋ค ๐
Q75.
const box = { x: 10, y: 20 };Object.freeze(box);const shape = box;shape.x = 100;console.log(shape);
- ์ ํ์ง
- A:
{ x: 100, y: 20 }
- B:
{ x: 10, y: 20 }
- C:
{ x: 100 }
- D:
ReferenceError
- A:
- ๋ต: B
๋ณ์ box
์ shape
๋ ๊ฐ์ ๊ฐ์ฒด๋ฅผ ์ฐธ์กฐํ๊ณ ์๋ค. L3์์ ํด๋น ๊ฐ์ฒด๋ฅผ ๋๊ฒฐ์์ผฐ๊ธฐ ๋๋ฌธ์ L6์์ ์์ ์ด ๋ถ๊ฐ๋ฅํ๋ค.
Q76.
const { name: myName } = { name: "Lydia" };console.log(name);
- ์ ํ์ง
- A:
"Lydia"
- B:
"myName"
- C:
undefined
- D:
ReferenceError
- A:
- ๋ต: D
๊ฐ์ฒด ๊ตฌ์กฐ ๋ถํด ํ ๋น, ํ๋กํผํฐ ํค๋ฅผ ๊ธฐ์ค์ผ๋ก ๊ตฌ์กฐ ๋ถํด ํ ๋น์ด ์ด๋ฃจ์ด์ง๋ค.
myName
์ ๋ฌธ์์ด ๊ฐ์ด ์๋๋ผ ์๋ณ์์ด๋ค.
์ฐธ์กฐ
- ๊ตฌ์กฐ ๋ถํด ํ ๋น | javascript.info
- ๊ตฌ์กฐ ๋ถํด ํ ๋น - JavaScript | MDN
- tc39/proposal-object-rest-spread
Q77. ์ด๊ฒ์ pure ํจ์ ์ผ๊น์?
function sum(a, b) {return a + b;}
- ์ ํ์ง
- A: Yes
- B: No
- ๋ต: A
์์ ํจ์๋ ํญ์ ๊ฐ์ ๊ฒฐ๊ณผ๋ฅผ ๋ฐํํ๋ค.
ํจ์ sum
์ ์ ๋ฌ๋๋ ๊ฐ์ด ๋์ผํ๋ค๋ฉด ํญ์ ๊ฐ์ ๊ฒฐ๊ณผ๋ฅผ ๋ฐํํ๊ธฐ ๋๋ฌธ์ ์์ ํจ์์ด๋ค.
Q78.
const add = () => {const cache = {};return num => {if (num in cache) {return `From cache! ${cache[num]}`;} else {const result = num + 10;cache[num] = result;return `Calculated! ${result}`;}};};const addFunction = add();console.log(addFunction(10));console.log(addFunction(10));console.log(addFunction(5 * 2));
- ์ ํ์ง
- A:
Calculated! 20
Calculated! 20
Calculated! 20
- B:
Calculated! 20
From cache! 20
Calculated! 20
- C:
Calculated! 20
From cache! 20
From cache! 20
- D:
Calculated! 20
From cache! 20
Error
- A:
- ๋ต: C
Q79.
const myLifeSummedUp = ["โ", "๐ป", "๐ท", "๐ซ"]for (let item in myLifeSummedUp) {console.log(item);}for (let item of myLifeSummedUp) {console.log(item);}
- ์ ํ์ง
- A:
0
1
2
3
๊ทธ๋ฆฌ๊ณ"โ"
"๐ป"
"๐ท"
"๐ซ"
- B:
"โ"
"๐ป"
"๐ท"
"๐ซ"
๊ทธ๋ฆฌ๊ณ"โ"
"๐ป"
"๐ท"
"๐ซ"
- C:
"โ"
"๐ป"
"๐ท"
"๐ซ"
๊ทธ๋ฆฌ๊ณ0
1
2
3
- D:
0
1
2
3
๊ทธ๋ฆฌ๊ณ{0: "โ", 1: "๐ป", 2: "๐ท", 3: "๐ซ"}
- A:
- ๋ต: A
Q80.
const list = [1 + 2, 1 * 2, 1 / 2]console.log(list);
- ์ ํ์ง
- A:
["1 + 2", "1 * 2", "1 / 2"]
- B:
["12", 2, 0.5]
- C:
[3, 2, 0.5]
- D:
[1, 1, 1]
- A:
- ๋ต: C
Q81.
function sayHi(name) {return `Hi there, ${name}`}console.log(sayHi());
- ์ ํ์ง
- A:
Hi there,
- B:
Hi there, undefined
- C:
Hi there, null
- D:
ReferenceError
- A:
- ๋ต: B
Q82.
var status = "๐";setTimeout(() => {const status = "๐";const data = {status: "๐ฅ",getStatus() {return this.status;}};console.log(data.getStatus());console.log(data.getStatus.call(this));}, 0);
- ์ ํ์ง
- A:
"๐ฅ"
๊ทธ๋ฆฌ๊ณ"๐"
- B:
"๐ฅ"
๊ทธ๋ฆฌ๊ณ"๐"
- C:
"๐"
๊ทธ๋ฆฌ๊ณ"๐"
- D:
"๐"
๊ทธ๋ฆฌ๊ณ"๐"
- A:
- ๋ต: B
Q83.
const person = {name: "Lydia",age: 21};let city = person.city;city = "Amsterdam";console.log(person);
- ์ ํ์ง
- A:
{ name: "Lydia", age: 21 }
- B:
{ name: "Lydia", age: 21, city: "Amsterdam" }
- C:
{ name: "Lydia", age: 21, city: undefined }
- D:
"Amsterdam"
- A:
- ๋ต: A
L6, ๋ณ์ city
๋ '๊ฐ์ฒด person
'์ด ๊ฐ์ง๋ 'ํ๋กํผํฐ city
'๋ฅผ ์ฐธ์กฐํ๋๋ฐ person.city
๋ ์กด์ฌํ์ง ์๊ธฐ ๋๋ฌธ์ ๋ณ์ city
์ ๊ฐ์ undefined
์ด๋ค.
L7, ๋ณ์ city
์ ๊ฐ์ด ๋ฌธ์์ด "Amsterdam"
์ผ๋ก ๋ณ๊ฒฝ ๋์์ ๋ฟ, ๊ฐ์ฒด person
์ ์ํฅ์ ์ฃผ์ง ์๋๋ค.
Q84.
function checkAge(age) {if (age < 18) {const message = "Sorry, you're too young.";} else {const message = "Yay! You're old enough!";}return message;}console.log(checkAge(21));
- ์ ํ์ง
- A:
"Sorry, you're too young."
- B:
"Yay! You're old enough!"
- C:
ReferenceError
- D:
undefined
- A:
- ๋ต: C
let
, const
ํค์๋๋ฅผ ์ฌ์ฉํด ์ ์ธํ ๋ณ์๋ ๋ธ๋ก ์ค์ฝํ๋ฅผ ๊ฐ๋๋ค.
Q85. ์ด๋ค ์ข ๋ฅ์ ์ ๋ณด๊ฐ ์ถ๋ ฅ๋ ๊น์?
fetch('https://www.website.com/api/user/1').then(res => res.json()).then(res => console.log(res));
- ์ ํ์ง
- A:
fetch
๋ฉ์๋์ ๊ฒฐ๊ณผ - B:
fetch
๋ฉ์๋์ ๋๋ฒ์งธ ํธ์ถ ๊ฒฐ๊ณผ - C: ์ด์
.then()
์์ callback๋ ๊ฒฐ๊ณผ - D: ํญ์ undefined
- A:
- ๋ต: C
Q86. true
๋ฅผ ์ธ์๋ก ์ ๋ฌ ํ ์ ์๋๋ก ์ฃผ์ด์ก์ ๋, hasName
์ true
๋ก ์ค์ ํ ์ ์๋ ๋ฐฉ๋ฒ์ ์ด๋ ๊ฒ ์ผ๊น์?
function getName(name) {const hasName = //}
- ์ ํ์ง
- A:
!!name
- B:
name
- C:
new Boolean(name)
- D:
name.length
- A:
- ๋ต: A
Q87.
console.log("I want pizza"[0]);
- ์ ํ์ง
- A:
"""
- B:
"I"
- C:
SyntaxError
- D:
undefined
- A:
- ๋ต: B
๋ฌธ์์ด์ ์ ์ฌ ๋ฐฐ์ด์ด๋ค.
Q88.
function sum(num1, num2 = num1) {console.log(num1 + num2)}sum(10)
- ์ ํ์ง
- A:
NaN
- B:
20
- C:
ReferenceError
- D:
undefined
- A:
- ๋ต: B
Q89.
// module.jsexport default () => "Hello world"export const name = "Lydia"// index.jsimport * as data from "./module"console.log(data)
- ์ ํ์ง
- A:
{ default: function default(), name: "Lydia" }
- B:
{ default: function default() }
- C:
{ default: "Hello world", name: "Lydia" }
- D: Global object of
module.js
- A:
- ๋ต: A
Q90.
class Person {constructor(name) {this.name = name}}const member = new Person("John")console.log(typeof member)
- ์ ํ์ง
- A:
"class"
- B:
"function"
- C:
"object"
- D:
"string"
- A:
- ๋ต: C
Q91.
let newList = [1, 2, 3].push(4)console.log(newList.push(5))
- ์ ํ์ง
- A:
[1, 2, 3, 4, 5]
- B:
[1, 2, 3, 5]
- C:
[1, 2, 3, 4]
- D:
Error
- A:
- ๋ต: D
Q74 ์ฐธ๊ณ
Q92.
function giveLydiaPizza() {return "Here is pizza!"}const giveLydiaChocolate = () => "Here's chocolate... now go hit the gym already."console.log(giveLydiaPizza.prototype)console.log(giveLydiaChocolate.prototype)
- ์ ํ์ง
- A:
{ constructor: ...}
{ constructor: ...}
- B:
{}
{ constructor: ...}
- C:
{ constructor: ...}
{}
- D:
{ constructor: ...}
undefined
- A:
- ๋ต: D
ํ์ดํ ํจ์๋ non-constructor์ด๊ธฐ ๋๋ฌธ์ ์์ฑ์ ํจ์๋ก ์ฌ์ฉํ ์ ์๋ค.
์์ฑ์ ํจ์๋ก ์ฌ์ฉํ ์ ์๋ค๋ ๊ฒ์ ์ธ์คํด์ค๋ฅผ ์์ฑํ ์ ์๋ค๋ ๋ป์ด๋ค.
์ฆ, ptototype ํ๋กํผํฐ๊ฐ ์๊ณ ํ๋กํ ํ์ ๋ ์์ฑํ์ง ์๋๋ค.
Q93.
const person = {name: "Lydia",age: 21};for (const [x, y] of Object.entries(person)) {console.log(x, y)}
- ์ ํ์ง
- A:
name
Lydia
๊ทธ๋ฆฌ๊ณage
21
- B:
["name", "Lydia"]
๊ทธ๋ฆฌ๊ณ["age", 21]
- C:
["name", "age"]
๊ทธ๋ฆฌ๊ณundefined
- D:
Error
- A:
- ๋ต: A
์ฐธ๊ณ - Object.entries() - JavaScript | MDN
Q94.
function getItems(fruitList, ...args, favoriteFruit) {return [...fruitList, ...args, favoriteFruit]}console.log(getItems(["banana", "apple"], "pear", "orange"));
- ์ ํ์ง
- A:
["banana", "apple", "pear", "orange"]
- B:
[["banana", "apple"], "pear", "orange"]
- C:
["banana", "apple", ["pear"], "orange"]
- D:
SyntaxError
- A:
- ๋ต: D
rest ํ๋ผ๋ฏธํฐ๋ ๋ง์ง๋ง์ ์ฌ์ฉํด์ผํ๋ค.
์ฐธ๊ณ - Rest ํ๋ผ๋ฏธํฐ - JavaScript | MDN
Q95.
function nums(a, b) {if(a > b)console.log('a is bigger')elseconsole.log('b is bigger')returna + b}console.log(nums(4, 2))console.log(nums(1, 2))
- ์ ํ์ง
- A:
a is bigger
,6
๊ทธ๋ฆฌ๊ณb is bigger
,3
- B:
a is bigger
,undefined
๊ทธ๋ฆฌ๊ณb is bigger
,undefined
- C:
undefined
๊ทธ๋ฆฌ๊ณundefined
- D:
SyntaxError
- A:
- ๋ต: B
์๋ฐ์คํฌ๋ฆฝํธ๋ ์ธ๋ฏธ์ฝ๋ก ์ ๋ช ์์ ์ผ๋ก ์ฌ์ฉํ์ง ์์๋ ์๋์ผ๋ก ์ฝ์ ํด์ค๋ค.
์ฐธ๊ณ - Q50
Q96.
class Person {constructor() {this.name = "Lydia"}}Person = class AnotherPerson {constructor() {this.name = "Sarah"}}const member = new Person()console.log(member.name)
- ์ ํ์ง
- A:
"Lydia"
- B:
"Sarah"
- C:
Error: cannot redeclare Person
- D:
SyntaxError
- A:
- ๋ต: B
Q97.
const info = {[Symbol('a')]: 'b'}console.log(info)console.log(Object.keys(info))
- ์ ํ์ง
- A:
{Symbol('a'): 'b'}
๊ทธ๋ฆฌ๊ณ["{Symbol('a')"]
- B:
{}
๊ทธ๋ฆฌ๊ณ[]
- C:
{ a: "b" }
๊ทธ๋ฆฌ๊ณ["a"]
- D:
{Symbol('a'): 'b'}
๊ทธ๋ฆฌ๊ณ[]
- A:
- ๋ต: D
symbol์ ์ด๊ฑฐ๊ฐ ๋ถ๊ฐ๋ฅํ๋ค.
Q98.
const getList = ([x, ...y]) => [x, y]const getUser = user => { name: user.name, age: user.age }const list = [1, 2, 3, 4]const user = { name: "Lydia", age: 21 }console.log(getList(list))console.log(getUser(user))
- ์ ํ์ง
- A:
[1, [2, 3, 4]]
๊ทธ๋ฆฌ๊ณundefined
- B:
[1, [2, 3, 4]]
๊ทธ๋ฆฌ๊ณ{ name: "Lydia", age: 21 }
- C:
[1, 2, 3, 4]
๊ทธ๋ฆฌ๊ณ{ name: "Lydia", age: 21 }
- D:
Error
๊ทธ๋ฆฌ๊ณ{ name: "Lydia", age: 21 }
- A:
- ๋ต: A
L2, ๋ฐํํ๋ ๊ฐ์ฒด๋ฅผ ์๊ดํธ๋ก ๊ฐ์ธ์ผํ๋ค.
Q99.
const name = "Lydia"console.log(name())
- ์ ํ์ง
- A:
SyntaxError
- B:
ReferenceError
- C:
TypeError
- D:
undefined
- A:
- ๋ต: C
p.s - ์ธ๋ฏธ์ฝ๋ก ๊ณ์ ์๋ถ์ด ์๋๊ฑฐ ์ ๊ฒฝ์ฐ์ฌ ์ฃฝ๊ฒ ๋ค
Q100.
// ๐โจ ์ด๋ฒ์ด ๋ด 100๋ฒ์งธ ์ง๋ฌธ์ด์์! โจ๐const output = `${[] && 'Im'}possible!You should${'' && `n't`} see a therapist after so much JavaScript lol`
- ์ ํ์ง
- A:
possible! You should see a therapist after so much JavaScript lol
- B:
Impossible! You should see a therapist after so much JavaScript lol
- C:
possible! You shouldn't see a therapist after so much JavaScript lol
- D:
Impossible! You shouldn't see a therapist after so much JavaScript lol
- A:
- ๋ต: B
Q101.
const one = (false || {} || null)const two = (null || false || "")const three = ([] || 0 || true)console.log(one, two, three)
- ์ ํ์ง
- A:
false
null
[]
- B:
null
""
true
- C:
{}
""
[]
- D:
null
null
true
- A:
- ๋ต: C
Q102.
const myPromise = () => Promise.resolve('I have resolved!')function firstFunction() {myPromise().then(res => console.log(res))console.log('second')}async function secondFunction() {console.log(await myPromise())console.log('second')}firstFunction()secondFunction()
- ์ ํ์ง
- A:
I have resolved!
,second
๊ทธ๋ฆฌ๊ณI have resolved!
,second
- B:
second
,I have resolved!
๊ทธ๋ฆฌ๊ณsecond
,I have resolved!
- C:
I have resolved!
,second
๊ทธ๋ฆฌ๊ณsecond
,I have resolved!
- D:
second
,I have resolved!
๊ทธ๋ฆฌ๊ณI have resolved!
,second
- A:
- ๋ต: D
async
await
ํค์๋๋ฅผ ์ฌ์ฉํ๋ฉด promise๊ฐ resoloved ๋ ๋๊น์ง ๊ธฐ๋ค๋ฆฌ๊ฒ ํ ์ ์๋ค.
Q103.
const set = new Set()set.add(1)set.add("Lydia")set.add({ name: "Lydia" })for (let item of set) {console.log(item + 2)}
- ์ ํ์ง
- A:
3
,NaN
,NaN
- B:
3
,7
,NaN
- C:
3
,Lydia2
,[object Object]2
- D:
"12"
,Lydia2
,[object Object]2
- A:
- ๋ต: C
Q104.
Promise.resolve(5)
- ์ ํ์ง
- A:
5
- B:
Promise {: 5}
- C:
Promise {: 5}
- D:
Error
- A:
- ๋ต: C
Q105.
function compareMembers(person1, person2 = person) {if (person1 !== person2) {console.log("Not the same!")} else {console.log("They are the same!")}}const person = { name: "Lydia" }compareMembers(person)
- ์ ํ์ง
- A:
Not the same!
- B:
They are the same!
- C:
ReferenceError
- D:
SyntaxError
- A:
- ๋ต: B
Q106.
const colorConfig = {red: true,blue: false,green: true,black: true,yellow: false,}const colors = ["pink", "red", "blue"]console.log(colorConfig.colors[1])
- ์ ํ์ง
- A:
true
- B:
false
- C:
undefined
- D:
TypeError
- A:
- ๋ต: D
Q107.
console.log('โค๏ธ' === 'โค๏ธ')
- ์ ํ์ง
- A:
true
- B:
false
- A:
- ๋ต: A
Q108. ๋ค์ ์ค ์๋ณธ ๋ฐฐ์ด์ ์์ ํ๋ method๋ ๋ฌด์์ผ๊น์?
const emojis = ['โจ', '๐ฅ', '๐']emojis.map(x => x + 'โจ')emojis.filter(x => x !== '๐ฅ')emojis.find(x => x !== '๐ฅ')emojis.reduce((acc, cur) => acc + 'โจ')emojis.slice(1, 2, 'โจ')emojis.splice(1, 2, 'โจ')
- ์ ํ์ง
- A:
All of them
- B:
map
reduce
slice
splice
- C:
map
slice
splice
- D:
splice
- A:
- ๋ต: D
Array.prototype.map
: ๋ฐฐ์ด์ ๊ฐ ์์์ ์ฝ๋ฐฑ ํจ์์ ๋ฐํ๊ฐ์ผ๋ก ์๋ก์ด ๋ฐฐ์ด์ ์์ฑํ์ฌ ๋ฐํํ๋ค.
Array.prototype.filter
: ์ฝ๋ฐฑ ํจ์์ ์คํ ๊ฒฐ๊ณผ๊ฐ true
์ธ ์์์ ๊ฐ๋ง ์ถ์ถํ์ฌ ์๋ก์ด ๋ฐฐ์ด์ ์์ฑํ์ฌ ๋ฐํํ๋ค.
Array.prototype.find
: ์ฝ๋ฐฑ ํจ์๋ฅผ ์คํํ์ฌ ๊ทธ ๊ฒฐ๊ณผ๊ฐ true
์ธ ์ฒซ ๋ฒ์งธ ์์๋ฅผ ๋ฐํํ๋ค.
Array.prototype.reduce
: ๊ฐ ์์์ ๋ฆฌ๋์ ํจ์(์ด์ ์ ์ฝ๋ฐฑ ํจ์ ์คํ ๋ฐํ๊ฐ์ ์ ๋ฌ)๋ฅผ ์คํํ๊ณ ๊ทธ ๊ฒฐ๊ณผ๋ฅผ ๋ฐํํ๋ค.
Array.prototype.slice
: ์ธ์๋ก ์ฃผ์ด์ง ๋ฐฐ์ด์ ์์๊ณผ ๋ ์ธ๋ฑ์ค๋ฅผ ๊ธฐ์ค์ผ๋ก ์์ ๋ณต์ฌ๋ฅผ ํ์ฌ ์๋ก์ด ๋ฐฐ์ด์ ๋ฐํํ๋ค.
Array.prototype.splice
: ์๋ณธ ๋ฐฐ์ด์ ๊ธฐ์กด ์์๋ฅผ ์ญ์ , ๊ต์ฒดํ๊ฑฐ๋ ์๋ก์ด ์์๋ฅผ ์ถ๊ฐํ๋ค.
Q109.
const food = ['๐', '๐ซ', '๐ฅ', '๐']const info = { favoriteFood: food[0] }info.favoriteFood = '๐'console.log(food)
- ์ ํ์ง
- A:
['๐', '๐ซ', '๐ฅ', '๐']
- B:
['๐', '๐ซ', '๐ฅ', '๐']
- C:
['๐', '๐', '๐ซ', '๐ฅ', '๐']
- D:
ReferenceError
- A:
- ๋ต: A
์ด๋ชจํฐ์ฝ์ ๋ฌธ์์ด์ด๋ค. ๋ฐ๋ผ์ L2์ favoriteFood: food[0]
๊ฐ์ด ํ ๋น์ํ๋ฉด pass-by-value๋ก ๊ฐ ์์ฒด๋ฅผ ๋ณต์ฌํ์ฌ ์ ๋ฌํ๊ณ ํ ๋นํ๊ธฐ ๋๋ฌธ์ ์ด ํ L4์์ info.favoriteFood = '๐'
๊ฐ์ด ๊ฐ์ ๋ณ๊ฒฝํ๋๋ผ๋ food[0]
์ ๊ฐ์ ์ํฅ์ ์ฃผ์ง ์๋๋ค.
Q110. ์ด ๋ฉ์๋๋ ๋ฌด์์ ํ ๊น์?
JSON.parse()
- ์ ํ์ง
- A: Parses JSON to a JavaScript value
- B: Parses a JavaScript object to JSON
- C: Parses any JavaScript value to JSON
- D: Parses JSON to a JavaScript object only
- ๋ต: A
JSON ๋ฌธ์์ด์ ๊ตฌ๋ฌธ์ผ๋ก JavaScript ๊ฐ์ด๋ ๊ฐ์ฒด๋ฅผ ์์ฑํ๋ค.
- p.s - ์ด ๋ฌธ์ ์ ์ ํ์ง๋ง ํด์์ด ์๋์ด ์์ด ์ถ๊ฐ
- A: JSON์ ์๋ฐ์คํฌ๋ฆฝํธ์ ๊ฐ์ผ๋ก ๋ณํํ๋ค.
- B: ์๋ฐ์คํฌ๋ฆฝํธ์ ๊ฐ์ฒด๋ฅผ JSON์ผ๋ก ๋ณํํ๋ค.
- C: ์ด๋ค ์๋ฐ์คํฌ๋ฆฝํธ ๊ฐ์ด๋ JSON์ผ๋ก ๋ณํํ๋ค.
- D: JSON์ ์๋ฐ์คํฌ๋ฆฝํธ์ ๊ฐ์ฒด๋ก๋ง ๋ณํํ๋ค.
Parse๋ผ๋ ๋จ์ด์ ๋ป์ ๊ตฌ๋ฌธ ๋ถ์, ํน์ ๊ตฌ๋ฌธ ๋ถ์ ๊ณผ์ ๊ทธ ์์ฒด๋ฅผ ์๋ฏธํ๋๊ฒ ๋ง์ง๋ง ์ดํดํ๊ธฐ ์ฝ๊ฒ '๋ณํ'์ด๋ผ๋ ๋จ์ด๋ฅผ ์ฌ์ฉํ์๋ค.
Q111.
let name = 'Lydia'function getName() {console.log(name)let name = 'Sarah'}getName()
- ์ ํ์ง
- A: Lydia
- B: Sarah
- C:
undefined
- D:
ReferenceError
- ๋ต: D
L5, ๋ณ์ name์ ํธ์ด์คํ ๋์ง๋ง ์ด๊ธฐํ๊ฐ ์ด๋ฃจ์ด์ง์ง ์์๊ธฐ ๋๋ฌธ์ ReferenceError๊ฐ ๋ฐ์ํ๋ค.
Q112.
function* generatorOne() {yield ['a', 'b', 'c'];}function* generatorTwo() {yield* ['a', 'b', 'c'];}const one = generatorOne()const two = generatorTwo()console.log(one.next().value)console.log(two.next().value)
- ์ ํ์ง
- A:
a
๊ทธ๋ฆฌ๊ณa
- B:
a
๊ทธ๋ฆฌ๊ณundefined
- C:
['a', 'b', 'c']
๊ทธ๋ฆฌ๊ณa
- D:
a
๊ทธ๋ฆฌ๊ณ['a', 'b', 'c']
- A:
- ๋ต: C
Q113.
console.log(`${(x => x)('I love')} to program`)
- ์ ํ์ง
- A:
I love to program
- B:
undefined to program
- C:
${(x => x)('I love') to program
- D:
TypeError
- A:
- ๋ต: A
Q114.
let config = {alert: setInterval(() => {console.log('Alert!')}, 1000)}config = null
- ์ ํ์ง
- A:
setInterval
์ฝ๋ฐฑ์ ํธ์ถ๋์ง ์์๊ฑฐ์์ - B:
setInterval
์ฝ๋ฐฑ์ ํ ๋ฒ๋ง ํธ์ถ๋ผ์ - C:
setInterval
์ฝ๋ฐฑ์ ์ฌ์ ํ ๋งค ์ด๋ง๋ค ํธ์ถ๋ผ์ - D: ๊ฒฐ์ฝ
config.alert()
๋ฅผ ํธ์ถ ํ์ง ์๊ณ , config ๋null
์ด์์
- A:
- ๋ต: C
Q115. ์ด๋ method๊ฐ ๊ฐ 'Hello world!'
๋ฅผ ๋ฆฌํด ํ ๊น์?
const myMap = new Map()const myFunc = () => 'greeting'myMap.set(myFunc, 'Hello world!')//1myMap.get('greeting')//2myMap.get(myFunc)//3myMap.get(() => 'greeting')
- ์ ํ์ง
- A: 1
- B: 2
- C: 2 ๊ทธ๋ฆฌ๊ณ 3
- D: ๋ชจ๋
- ๋ต: B
Q116.
const person = {name: "Lydia",age: 21}const changeAge = (x = { ...person }) => x.age += 1const changeAgeAndName = (x = { ...person }) => {x.age += 1x.name = "Sarah"}changeAge(person)changeAgeAndName()console.log(person)
- ์ ํ์ง
- A:
{name: "Sarah", age: 22}
- B:
{name: "Sarah", age: 23}
- C:
{name: "Lydia", age: 22}
- D:
{name: "Lydia", age: 23}
- A:
- ๋ต: C
p.s - ์ด๋์ ํ๊ตญ์ด๋ก ๋ฒ์ญ๋ ๋ฌธ์ ๋ ์ด์ ๋ค ํ์๋ค
Q117. Which of the following options will return 6
?
function sumValues(x, y, z) {return x + y + z;}
- ์ ํ์ง
- A:
sumValues([...1, 2, 3])
- B:
sumValues([...[1, 2, 3]])
- C:
sumValues(...[1, 2, 3])
- D:
sumValues([1, 2, 3])
- A:
- ๋ต: C
์คํ๋ ๋ ์ฐ์ฐ์๋ฅผ ์ฌ์ฉํด์ ๋ฐฐ์ด([1, 2, 3]
)์ด ์ ๊ฐ๋์ด ํจ์ sumValues()
์ ํ๋ผ๋ฏธํฐ x, y, z
์ ๋์
๋๋ค.
Q118.
let num = 1;const list = ['๐ฅณ', '๐ค ', '๐ฅฐ', '๐คช'];console.log(list[(num += 1)]);
- ์ ํ์ง
- A:
๐ค
- B:
๐ฅฐ
- C:
SyntaxError
- D:
ReferenceError
- A:
- ๋ต: B
Q119.
const person = {firstName: 'Lydia',lastName: 'Hallie',pet: {name: 'Mara',breed: 'Dutch Tulip Hound',},getFullName() {return `${this.firstName} ${this.lastName}`;},};console.log(person.pet?.name);console.log(person.pet?.family?.name);console.log(person.getFullName?.());console.log(member.getLastName?.());
- ์ ํ์ง
- A:
undefined
undefined
undefined
undefined
- B:
Mara
undefined
Lydia Hallie
undefined
- C:
Mara
null
Lydia Hallie
null
- D:
null
ReferenceError
null
ReferenceError
- A:
- ๋ต:
์ ๋ต์ B๋ผ๊ณ ํ๋๋ฐ
Mara
undefined
Lydia Hallie
ReferenceError
์๋๊ฐ..?
Q120.
const groceries = ['banana', 'apple', 'peanuts'];if (groceries.indexOf('banana')) {console.log('We have to buy bananas!');} else {console.log(`We don't have to buy bananas!`);}
- ์ ํ์ง
- A: We have to buy bananas!
- B: We don't have to buy bananas
- C:
undefined
- D:
1
- ๋ต: B
Q121.
const config = {languages: [],set language(lang) {return this.languages.push(lang);},};console.log(config.language);
- ์ ํ์ง
- A:
function language(lang) { this.languages.push(lang }
- B:
0
- C:
[]
- D:
undefined
- A:
- ๋ต: D
์ ๊ทผ์ ํ๋กํผํฐ language
๋ getter๋ฅผ ์ค์ ํ์ง ์์ ์ฝ์ ์ ์๋ค.
setter๋ ๊ฐ์ ์ค์ ํ๋ ๋ฉ์๋์ด๊ธฐ ๋๋ฌธ์ language
์ ์ ๊ทผํ๋ฉด undefined
๋ฅผ ๋ฐํํ๋ค.
Q122.
const name = 'Lydia Hallie';console.log(!typeof name === 'object');console.log(!typeof name === 'string');
- ์ ํ์ง
- A:
false
true
- B:
true
false
- C:
false
false
- D:
true
true
- A:
- ๋ต: C
typeof
์ฐ์ฐ์๋ฅผ ์ฌ์ฉํ๋ฉด ํผ์ฐ์ฐ์์ ์๋ฃํ์ ๋ฌธ์์ด๋ก ๋ฐํํ๋ค.
๋ฐ๋ผ์ typeof name
์ 'string'
์ ๋ฐํ ํ์ง๋ง ์์ ๋
ผ๋ฆฌ NOT ์ฐ์ฐ์ !
์ฌ์ฉํ๊ธฐ ๋๋ฌธ์ false
๋ก ํ๊ฐ๋๋ค.
false === 'object'
, false === 'string'
์ false
Q123.
const add = x => y => z => {console.log(x, y, z);return x + y + z;};add(4)(5)(6);
- ์ ํ์ง
- A:
4
5
6
- B:
6
5
4
- C:
4
function
function
- D:
undefined
undefined
6
- A:
- ๋ต: A
Q124.
async function* range(start, end) {for (let i = start; i <= end; i++) {yield Promise.resolve(i);}}(async () => {const gen = range(1, 3);for await (const item of gen) {console.log(item);}})();
- ์ ํ์ง
- A:
Promise {1}
Promise {2}
Promise {3}
- B:
Promise {<pending>}
Promise {<pending>}
Promise {<pending>}
- C:
1
2
3
- D:
undefined
undefined
undefined
- A:
- ๋ต: C
Q125.
const myFunc = ({ x, y, z }) => {console.log(x, y, z);};myFunc(1, 2, 3);
- ์ ํ์ง
- A:
1
2
3
- B:
{1: 1}
{2: 2}
{3: 3}
- C:
{ 1: undefined }
undefined
undefined
- D:
undefined
undefined
undefined
- A:
- ๋ต: D
### Q.โ```javascriptโ```- **์ ํ์ง**-- **๋ต**: