Nullish-Coalescing

??

// โŒ Bad Code
function printMessage(text) {
  let message = text;
  if (text == null || text == undefined) {
    message = 'Nothing to display ๐Ÿ˜œ';
  }
  console.log(message);
}
// โœ… Good Code โœจ
function printMessage(text) {
  const message = text ?? 'Nothing to display ๐Ÿ˜œ';
  console.log(message);
}

const printMessage = text => {
	const message = test ?? "Noting~"
}

null, undefined์ธ ๊ฒฝ์šฐ ์˜ค๋ฅธ์ชฝ์„ ์‹คํ–‰ํ•œ๋‹ค

//์˜ˆ์‹œ
printMessage('Hello'); //Hello
printMessage(null); //Nothing to display ๐Ÿ˜œ
printMessage(undefined); //Nothing to display ๐Ÿ˜œ

Logical OR operator

||

false -0 0 NaN undefined null โ€œโ€ โ€˜โ€™ ``์ธ

๊ฒฝ์šฐ ์˜ค๋ฅธ์ชฝ์„ ์‹คํ–‰ํ•œ๋‹ค

 function printMessage(text) {
  const message = text || 'Nothing to display ๐Ÿ˜œ';
  console.log(message);
}

๊ฒฐ๋ก 

??์™€ ||์˜ ์ฐจ์ด์ ์€ ??๋Š” null๊ณผ undefined๋งŒ ํŒ๋ณ„์ด ๊ฐ€๋Šฅํ•˜๊ณ  ||๋Š” ์—ฌ๋Ÿฌ falsyํ•œ ๊ฐ’๋“ค์„ ์ด์šฉํ•ด ์กฐ๊ฑด์ฒ˜๋ฆฌ๋ฅผ ํ•  ์ˆ˜ ์žˆ์Œ