κΈ°λ³Έμ μΈ ν¨μ μμ±λ²
//ν¨μ μ μ
const double=function(x,y){
return x*2
}
//ν¨μ νΈμΆ
console.log('double :',double(7))
νμ΄ν ν¨μ
//ν¨μμ μΆμ½ν
//νμ΄ν ν¨μλ₯Ό μ΄μ©ν΄ κ°λ¨νκ² ν¨μλ₯Ό μμ±ν μ μλ€.
//const [ν¨μμ΄λ¦] = [(ν¨μ μΈμ- νλμ΄λ©΄ κ΄νΈ μλ΅κ°λ₯)] => [ν¨μκ° λ°νν λ΄μ©]
const doublearrow = x => x*2
console.log('doublearrow :',doublearrow(7))
//const [ν¨μμ΄λ¦] = [(ν¨μ μΈμ- μμΌλ©΄ κ΄νΈ)] => [ν¨μκ° λ°νν λ΄μ©]
const sh = x => ({name:'kite'})
console.log('sh :',sh(7))
μ¦μ μ€νν¨μ (IIFE)
μ¦μ μ€νν¨μ
IIFE - Immediately-Invoked Function Expression
const a=14;
//λ°©λ² 1 (function(){ν¨μλ΄μ©}());
(function(){
console.log(a*2)
}());
//λ°©λ² 2 (function(){ν¨μλ΄μ©})();
(function(){
console.log(a*2)
})();
νΈμ΄μ€ν (Hoisting)
νΈμ΄μ€ν - ν¨μ μ μΈλΆκ° μ ν¨λ²μ μ΅μλ¨μΌλ‘ λμ΄μ¬λ €μ§λ νμ
λ‘μ§μ΄ 볡μ‘ν λ μ½κ² μ½λμ νλ¦μ νμ ν μ μλ€.
const a=14;
//ν¨μ μ μΈμ΄ λ¨Όμ λ±μ₯
double2()
function double2(){
console.log(a+5)
}
'WEB > HTML+CSS+JS' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[JavaScript] ν¨μ μ 리 2 - νμ΄λ¨Έν¨μ, μ½λ°±(Callback) ν¨μ,λΉλκΈ° μ²λ¦¬λ°©μ (0) | 2021.07.08 |
---|---|
[JavaScript] document.write()ν¨μ μμΉ (0) | 2021.04.09 |
[CSS] μμ, νμ μ νμ μ°¨μ΄μ (0) | 2021.03.24 |
[HTML+CSS+JavaScript]νμ΄ν ν¨κ³Ό λλ© νμ΄μ§ λ§λ€κΈ° (0) | 2021.01.13 |
λ°λλΌ μ€ν¬λ¦½νΈ - part 3μ 리 (0) | 2021.01.04 |
λκΈ