let b = 'abcde'
let b = 'abcde'
console.log(b)// Error
var a = 'abcd'
var a = 'abcde'
console.log(a) // abcde
function sayHello () {
const hello = 'Hello, world!';
console.log(hello);
}
sayHello(); // 'Hello, world!'
console.log(hello) // Error, hello is not defined
{
const hello = 'Hello, world!'
console.log(hello) // 'Hello, world'
}
console.log(hello) // Error, hello is not defined
(호이스팅은 ‘끌어올리다’의 의미이다.)
// 이 코드의 결과는 아래의 코드와 같습니다.
sayHello();
function sayHello () {
console.log('Hello, world');
}
// 이 코드의 결과는 위의 코드의 결과와 같습니다.
function sayHello() {
console.log('Hello, world');
}
sayHello();
sayHello(); // Error, sayHello is not defined
const sayHello = function () {
console.log('Hello, world');
}
function first () {
const world = `I'm part of first`;
}
function second () {
first();
console.log(world); // Error, world is not defined
}
function outerFunction () {
const outer = `I'm the outer function!`;
function innerFunction() {
const inner = `I'm the inner function!`;
console.log(outer) // I'm the outer function!
}
console.log(inner); // Error, inner is not defined
}
function outerFunction () {
const outer = `I see the outer variable!`;
return function innerFunction () {
console.log(outer);
}
}
outerFunction()() // I see the outer variable!