함수의 기본 문법은 함수 선언문과 함수 표현식이 있다.
// 함수 선언문(Declaration)
function test() {}
// 함수 표현식(Expression)
const test() = function () {}
또한 호이스팅(Hoisting)은 함수 선언부가 유효 범위 최상단으로 끌어올려지는 현상을 말한다.
// 호이스팅(Hoisting)
function test1() {
console.log('Test1')
}
test1() // Test1
test2() // test2
function test2() {
console.log('test2')
}
하지만 함수 표현식으로 함수를 표현하면 호이스팅이 발생하지 않는다.
test() // Uncaught ReferenceError: test is not defined
const test = function () {
console.log(test)
}
'패스트캠퍼스' 카테고리의 다른 글
javaScript-함수(매개변수 패턴) (0) | 2023.05.15 |
---|---|
javaScript-함수(반환 및 종료) (0) | 2023.05.15 |
javaScript-while, do while 반복문 (0) | 2023.04.24 |
javaScript-For, For of, For in 반복문 (0) | 2023.04.24 |
javaScript-if, switch 조건문 (0) | 2023.04.24 |