Skip to content

Latest commit

ย 

History

History
19 lines (16 loc) ยท 719 Bytes

[20201101]_optional_chaining.md

File metadata and controls

19 lines (16 loc) ยท 719 Bytes

Optional chaining (?.)

  • ํ”„๋กœํผํ‹ฐ๊ฐ€ ์—†๋Š” ์ค‘์ฒฉ ๊ฐ์ฒด์— ์—๋Ÿฌ ์—†์ด ์•ˆ์ „ํ•˜๊ฒŒ ์ ‘๊ทผ
  • ๋Œ€์ƒ์ด undefined๋‚˜ null์ด๋ฉด undefined ๋ฐ˜ํ™˜
  • ๋‚จ์šฉํ•˜์ง€ ๋ง ๊ฒƒ
    • ๋ฐ˜๋“œ์‹œ ์žˆ์–ด์•ผ ํ•˜๋Š” ๊ฐ’์— ๊ฐ’์ด ์—†์„ ๊ฒฝ์šฐ, ์—๋Ÿฌ๋ฅผ ํ†ตํ•ด ๋ฐ”๋กœ ๋ฐœ๊ฒฌํ•ด์•ผ ํ•˜๋Š”๋ฐ ์—๋Ÿฌ๋ฅผ ๊ฐ์ถ”๋ฏ€๋กœ ๋””๋ฒ„๊น…์ด ์–ด๋ ค์šธ ์ˆ˜ ์žˆ๋‹ค.

์˜ˆ์ œ

const fish = null;

//console.log(fish.type);        // Cannot read property 'type' of null
console.log(fish && fish.type);  // null
console.log(fish?.type);         // undefined
* References