
const global = '전역입니다.';
const text = '안녕하세요';
let name = 'Kim';
const sayHello = (text, name) => `${text}. ${name}입니다.`
const print = (text) => {
let name = 'Lee';
const innerFunc = () => {
let name = 'park';
console.log(global);
console.log(name);
}
console.log(text);
console.log(name);
innerFunc();
console.log(sayHello(text,name));
}
print('반갑습니다!');
console.log(sayHello(text,name));
console.log(sayHello(text,name)) 호출const sayHello = (text, name) => "${text}. ${name}입니다." 실행const text = '안녕하세요' let name = 'Kim'; 을 가져옴.print('반갑습니다!') 호출const print = (text) text에 반갑습니다.print안에 변수 찾기let name ="Lee" 찾으면 name은 Leeconst sayHello = (text, name) => "${text}. ${name}입니다." 가지고 있던, 반갑습니다와 Lee를 입력.console.log(sayHello(text, name)); 실행.innerFunc() 호출innerFunc 안에 실행문장 확인 name 출력 변수 선언 되있음. ParkinnerFunc 안에 global 변수 선언 없어서 바깥(전역)으로 찾으러 감.const global = "전역입니다." global 변수를 찾음. 전역입니다.console.log(text); console.log(name); 실행sayHello 실행 -> print 실행 -> innerFunc 실행 -> innerFunc 종료 -> print 종료 -> sayHello 종료
(이게 맞는 순서인가..🤨 몰겟다...)
function foo() {
let name = 'Kim'
function bar() {
console.log(name);
}
bar();
}
foo();
var name = 'lee';
정답은 Kim
힘!🔥🔥🔥🔥🔥🔥