var, let, const / Template literal / == vs ===


λ³€μˆ˜ μ„ μ–Έ ν‚€μ›Œλ“œ var / let / const


  • λ³€μˆ˜ μ„ μ–Έ ν‚€μ›Œλ“œλŠ” 쓰지 μ•Šμ•„λ„ λ˜μ§€λ§Œ, μ“°λŠ” 게 μ’‹λ‹€!

  • var

    • ES6 이전 μ‚¬μš©

    • λ¦¬ν„°λŸ΄ κ°’μ˜ μž¬ν• λ‹Ή κ°€λŠ₯

    • 이미 μ„ μ–Έλ˜μ–΄ μžˆλŠ” 이름과 같은 μ΄λ¦„μœΌλ‘œ λ³€μˆ˜λ₯Ό λ‹€μ‹œ 선언해도 μ—λŸ¬ λ°œμƒ X

    • λ³€μˆ˜ μ„ μ–Έ μ‹œ μ΄ˆκΈ°κ°’ μ§€μ •ν•˜μ§€ μ•Šμ•„λ„ 됨

  • let

    • 후에 λ³€κ²½ν•˜κ²Œ 될 λ³€μˆ˜μ— μ‚¬μš©

    • λ¦¬ν„°λŸ΄ κ°’μ˜ μž¬ν• λ‹Ή κ°€λŠ₯

        let age = 27;   <mutated
        age = 28;   
      
    • 이미 μ„ μ–Έλœ λ³€μˆ˜λͺ…μœΌλ‘œ μž¬μ„ μ–Έ λΆˆκ°€λŠ₯

    • λ³€μˆ˜ μ„ μ–Έ μ‹œ μ΄ˆκΈ°κ°’ μ§€μ •ν•˜μ§€ μ•Šμ•„λ„ 됨

        let year;
      
  • const

    • 후에 λ°”λ€Œμ§€ μ•Šμ„ 것 같은 λ³€μˆ˜μ— μ‚¬μš©

    • μž¬ν• λ‹Ή ν•˜λ©΄ μ—λŸ¬

    • 이미 μ„ μ–Έλœ λ³€μˆ˜λͺ…μœΌλ‘œ μž¬μ„ μ–Έ λΆˆκ°€λŠ₯

    • λ³€μˆ˜ μ„ μ–Έ μ‹œ μ΄ˆκΈ°κ°’ 지정해야 함



ν…œν”Œλ¦Ώ λ¦¬ν„°λŸ΄(Template literal)


  • λ°±ν‹±( ` )으둜 λ¬Έμžμ—΄ μ‚¬μš©

  • multiple-line strings

    • 일반 λ¬Έμžμ—΄ : \n μ‚¬μš©

    • console.log(`String
      multiple
      lines`);
      
  • ν”Œλ ˆμ΄μŠ€ν™€λ”(placeholder)λ₯Ό μ΄μš©ν•˜μ—¬ ν‘œν˜„μ‹ λ„£κΈ°

    • $와 μ€‘κ΄„ν˜Έλ‘œ ν‘œκΈ° : ` ${expression} `

    • ν‘œν˜„μ‹κ³Ό κ·Έ 사이 ν…μŠ€νŠΈλŠ” ν•¨κ»˜ ν•¨μˆ˜λ‘œ 전달됨

    • const firstName = 'Jinsol';
      
      const jinsol = "I'm " + firstName;
      console.log(jinsol);
      
      const jinsolNew = `I'm ${firstName}`;
      console.log(jinsolNew); 
      



== vs ===


  • == : Loose Equality Operator

    • κ°’λ§Œμ„ 비ꡐ해 κ°™μœΌλ©΄ true, λ‹€λ₯΄λ©΄ false

    • ex) 18 == β€˜18’ > true

  • === : Strict Equality Operator

    • κ°’κ³Ό κ°’μ˜ μ’…λ₯˜(Data Type)κΉŒμ§€ 비ꡐ해 κ°™μœΌλ©΄ true, λ‹€λ₯΄λ©΄ false

    • ex) 18 === β€˜18’ > false

Categories:

Javascript