๐ฉ ๋ ผ๋ฆฌ์ AND(&&)
๋
ผ๋ฆฌ์ AND (&&)์ ํผ์ฐ์ฐ์๋ฅผ ์ผ์ชฝ์์ ์ค๋ฅธ์ชฝ์ผ๋ก ํ๊ฐํ๋ฉด์ ์ฒซ ๊ฑฐ์ง ๊ฐ์ ํผ์ฐ์ฐ์๋ฅผ ๋ง๋๋ฉด ์ฆ์ ๊ทธ ๊ฐ์ ๋ฐํํฉ๋๋ค. ๋ง์ฝ ๋ชจ๋ ๊ฐ์ด ์ฐธ ๊ฐ์ ๊ฐ์ด๋ผ๋ฉด ๋ง์ง๋ง ํผ์ฐ์ฐ์์ ๊ฐ์ด ๋ฐํ๋ฉ๋๋ค.
๋ง์ฝ ์ด๋ค ๊ฐ์ด true๋ก ๋ณํ ๊ฐ๋ฅํ๋ค๋ฉด ๊ทธ ๊ฐ์ ์์ ์ฐธ ๊ฐ์ ๊ฐ(truthy)์ด๋ผ ํฉ๋๋ค. ๋ง์ฝ ์ด๋ค ๊ฐ์ด false๋ก ๋ณํ ๊ฐ๋ฅํ๋ค๋ฉด ๊ทธ ๊ฐ์ ์์ ๊ฑฐ์ง ๊ฐ์ ๊ฐ(falsy) ์ด๋ผ๊ณ ํฉ๋๋ค.
result = '' && 'foo'; // result ์ ""(๋น ๋ฌธ์์ด)์ด ํ ๋น๋ฉ๋๋ค
result = 2 && 0; // result ์ 0 ์ด ํ ๋น๋ฉ๋๋ค
result = 'foo' && 4; // result ์ 4 ๊ฐ ํ ๋น๋ฉ๋๋ค.
a1 = true && true // t && t returns true
a2 = true && false // t && f returns false
a3 = false && true // f && t returns false
a4 = false && (3 === 4) // f && f returns false
a5 = 'Cat' && 'Dog' // t && t returns "Dog"
a6 = false && 'Cat' // f && t returns false
a7 = 'Cat' && false // t && f returns false
a8 = '' && false // f && f returns ""
a9 = false && '' // f && f returns false
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Operators/Logical_AND
๋ ผ๋ฆฌ์ AND (&&) - JavaScript | MDN
๋ ผ๋ฆฌ์ AND (&&) (๋ ผ๋ฆฌ์ ์ฐ๊ฒฐ) ์ฐ์ฐ์๋ ๋ชจ๋ ๋ถ๋ฆฌ์ธ ํผ์ฐ์ฐ์๊ฐ true๊ฐ ๋์์ ๋ ํด๋น ํผ์ฐ์ฐ์์ ์งํฉ์true๊ฐ ๋ฉ๋๋ค.
developer.mozilla.org
๐ฉ ๋ ผ๋ฆฌ์ OR(||)
If x can be converted to true, returns x; else, returns y.
If a value can be converted to true, the value is so-called truthy. If a value can be converted to false, the value is so-called falsy.
true || true; // t || t returns true
false || true; // f || t returns true
true || false; // t || f returns true
false || 3 === 4; // f || f returns false
"Cat" || "Dog"; // t || t returns "Cat"
false || "Cat"; // f || t returns "Cat"
"Cat" || false; // t || f returns "Cat"
"" || false; // f || f returns false
false || ""; // f || f returns ""
false || varObject; // f || object returns varObject
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_OR
Logical OR (||) - JavaScript | MDN
The logical OR (||) (logical disjunction) operator for a set of operands is true if and only if one or more of its operands is true. It is typically used with boolean (logical) values. When it is, it returns a Boolean value. However, the || operator actual
developer.mozilla.org
โ๏ธ or and๋ฅผ ๊ฐ์ด ์ธ ๋ ์ฐ์ ์์๋?
"&&" >> "||"
“&&” - > ์ด๋์ด ๋ ์ฐ์ ์์ ๋์
true || false && false; // returns true, because && is executed first
(true || false) && false; // returns false, because grouping has the highest precedence
'IT > JavaScript' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[JS] โ๏ธ Infinity / ifFinite() (0) | 2023.07.17 |
---|---|
[JS] โ๏ธ NaN (Not a Number) / isNaN() (0) | 2023.07.17 |
[JS] โ๏ธ Nullish (??) (0) | 2023.07.17 |
[JS] โ๏ธ Truthy && Falsey (0) | 2023.07.17 |
[JS] โ๏ธ eval(), JSON.parse(), JSON.stringify() (0) | 2023.07.17 |