본문 바로가기

부트캠프교육중/JavaScript63

[JavaScript] 화살표함수 const add = function (x, y) { return x + y } const add = (x, y) => { return x + y } 두가지는 같은 의미이다. function키워드를 생략하고 화살표 =>를 붙인다. 2023. 1. 4.
[JavaScript] const # const로 선언된 객체의 경우, 속성을 추가하거나 삭제할수있다. const obj = { x: 1 }; // -> obj ={x:1} delete obj.x; // -> obj = {} const megalomaniac = { mastermind: 'Agent Smith', henchman: 'Agent Smith' }; megalomaniac.secretary = 'Agent Smith'; -> megalomaniac = { mastermind: 'Agent Smith', henchman: 'Agent Smith', secretary: 'Agent Smith'}; # const는 재할당이 금지된다. 하지만 할당된 객체의 내용은 변경할수 있다.(프로퍼티의 추가, 삭제, 프로퍼티 값의 변경) 객체의 .. 2023. 1. 4.
[JavaScript] scope문제풀이 function () { let age = 27; let name = 'jin'; let height = 179; function outerFn() { let age = 24; name = 'jimin'; let height = 178; function innerFn() { age = 26; let name = 'suga'; return height;} innerFn(); expect(age).to.equal(??); expect(name).to.equal(??); return innerFn; } const innerFn = outerFn(); expect(age).to.equal(??); expect(name).to.equal(??); expect(innerFn()).to.equal(??); }); }.. 2023. 1. 4.
[JavaScript] 스코프 문제 let x = 10; function outer () { let x = 20; function inner () { x = x + 10; return x; } inner(); } outer(); let result = x; // result 값은 얼마인가?? 1. 스코프를 그리면 저렇게 된다. 2. 답은 10이다. 3. 풀이 outer함수를 실행하면 outer함수 스코프 내에서 inner 함수가 호출된다. inner에 의해 값이 변경되는 x는 outer스코프에 속한 x입니다. inner가 실행되면서 outer함수 스코프의 변수 x값이 30으로 바뀐다. 하지만 변수 result에 할당된 값은 전역 스코프의 x이므로, outer함수가 호출되어도 아무런 영향을 받지 않는다. let x = 10; function.. 2023. 1. 3.