๋ฉ์์ง
SyntaxError: missing ) after condition
์๋ฌ ์ ํ
๋ฌด์์ด ์๋ชป ๋ ๊ฑธ๊น?
if
์กฐ๊ฑด๋ฌธ์ ์๋ฌ๊ฐ ์์ต๋๋ค. ์ด๋ ํ ํ๋ก๊ทธ๋๋ฐ ์ธ์ด์์๋ ์ฝ๋๋ ์
๋ ฅ๊ฐ์ ๋ฐ๋ผ ์์ฌ๋ฅผ ๊ฒฐ์ ํ๊ณ ํ๋์ ์ํํด์ผํฉ๋๋ค. ์ง์ ๋ ์กฐ๊ฑด์ด true์ด๋ฉด if ๋ฌธ์ด ๋ช
๋ น๋ฌธ์ ์คํํฉ๋๋ค. ์๋ฐ์คํฌ๋ฆฝํธ์์๋ ์ด ์กฐ๊ฑด์ด if
๋ฌธ ๋ค์์ ๊ดํธ์ ์์ด์ผ ํฉ๋๋ค. ๋ค์์ ๊ทธ ์์์
๋๋ค.
if (condition) {
// do something if the condition is true
}
์์
์ค์๊ฐ ์์ ์ ์์ผ๋, ๋ชจ๋ ๊ดํธ๋ฅผ ์ฃผ์๊น๊ฒ ํ์ธํ์ธ์.
if (3 > Math.PI {
console.log("wait what?");
}
// SyntaxError: missing ) after condition
์ด ์ฝ๋๋ฅผ ๊ณ ์น๊ธฐ ์ํด์ , ์กฐ๊ฑด๋ฌธ์ ๊ดํธ๋ก ๋ซ์์ผ ํฉ๋๋ค.
if (3 > Math.PI) {
console.log("wait what?");
}
๋ค๋ฅธ ํ๋ก๊ทธ๋๋ฐ ์ธ์ด๋ฅผ ๋ฐฐ์ด ๊ฒฝ์ฐ, ์๋ฐ์คํฌ๋ฆฝํธ์์๋ ๋ค๋ฅด๊ฒ ์ฐ์ด๊ฑฐ๋, ์ฐ์ด์ง ์๋ ํค์๋๋ฅผ ์ฌ์ฉํ๊ธฐ ์ฝ์ต๋๋ค.
if (done is true) {
console.log("we are done!");
}
// SyntaxError: missing ) after condition
์ด ๊ฒฝ์ฐ ์ฌ๋ฐ๋ฅธ ๋น๊ต์ฐ์ฐ์๋ฅผ ์ฌ์ฉํด์ผ ํฉ๋๋ค. ๊ทธ ์์๋ก:
if (done === true) {
console.log("we are done!");
}