ReferenceError: invalid assignment left-hand side

๋ฉ”์‹œ์ง€

    ReferenceError: invalid assignment left-hand side

์—๋Ÿฌ ํƒ€์ž…

๋ฌด์—‡์ด ์ž˜๋ชป๋˜์—ˆ์„๊นŒ?

์˜ˆ์ƒ์น˜ ๋ชปํ•œ ํ• ๋‹น์ด ์ผ์–ด๋‚ฌ์Šต๋‹ˆ๋‹ค. ์ด๊ฒƒ์€ ํ• ๋‹น ์—ฐ์‚ฐ์ž(assignment operator)์™€ ๋น„๊ต ์—ฐ์‚ฐ์ž(comparison operator) ๊ฐ„์˜ ๋ถˆ์ผ์น˜๋กœ ์ธํ•œ ๊ฒƒ์ผ ๊ฒ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค๋ฉด, "=" ๋ถ€ํ˜ธ๋Š” ๊ฐ’์„ ๋ณ€์ˆ˜์— ํ• ๋‹นํ•ฉ๋‹ˆ๋‹ค. "==" ๋‚˜ "==="๋Š” ๊ฐ’์„ ๋น„๊ตํ•˜๋Š” ์—ฐ์‚ฐ์„ ํ•ฉ๋‹ˆ๋‹ค.

์˜ˆ

js
if (Math.PI = 3 || Math.PI = 4) {
  console.log('no way!');
}
// ReferenceError: invalid assignment left-hand side

var str = 'Hello, '
+= 'is it me '
+= 'you\'re looking for?';
// ReferenceError: invalid assignment left-hand side

if ๊ตฌ๋ฌธ์—์„œ, ๋น„๊ต ์—ฐ์‚ฐ์ž ("==")๋กœ ๋น„๊ตํ•˜๋ ค ํ•  ๋•Œ, ๋ฌธ์ž์—ด์˜ ์—ฐ์†์ ์ธ ๊ฒฐํ•ฉ์˜ ๊ฒฝ์šฐ์—๋Š”, ํ”Œ๋Ÿฌ์Šค("+") ์—ฐ์‚ฐ์ž๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

js
if (Math.PI == 3 || Math.PI == 4) {
  console.log("no way!");
}

var str = "Hello, " + "from the " + "other side!";

์ฐธ์กฐ