operators-function-control-flow
Operator
false || true && false
์ฐ์ฐ์ ์ฐ์ ์์๊ฐ ์๋ค. ์ฌ๋์ด ์ฝ๋๊ฒ ์ฝ๋์ด๊ธฐ ๋๋ฌธ์ ๋จผ์ ์ฐ์ฐ๋๊ธธ ๋ฐ๋ผ๋ ๊ณณ์ ๊ดํธ๋ฅผ ๋จผ์ ํ๋๊ฒ ์ข๋ค.
[MDN ๋ ผ๋ฆฌ์ฐ์ฐ์ ์์๋ณด๊ธฐ]([https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Operators/%EB%85%BC%EB%A6%AC_%EC%97%B0%EC%82%B0%EC%9E%90(Logical_Operators)](https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Operators/๋ ผ๋ฆฌ_์ฐ์ฐ์(Logical_Operators))
Function
arguments
function add(x, y) {
console.log(arguments[0]);
console.log(arguments.length);
return x + y;
}
์ ์ฌ๋ฐฐ์ด์ด๋ผ๊ณ ํ ์ ์๋ค.
function add(x, y){
return function bar () {};
}
console.log(add() || 3) //function bar() {};
console.log(add()() || 3); //3
์ฒซ๋ฒ์งธ console ์ฐ์๊ฑด return ๋ค์์ function bar () {}; ๋ฅผ ๋ํ๋ธ๋ค. ๋๋ฒ์งธ console ์ฐ์๊ฑด bar๋ฅผ ๋ํ๋ด๋๋ฐ returnํ๋๊ฒ ์๊ธฐ๋๋ฌธ์ undefined๋ค
return
function a(b){
return
}
console.log(a); //undefined
return์ return ๋ฌธ๊ตฌ๋ฅผ ์คํ์ํค๊ณ function์ ์ข ๋ฃ ์ํจ๋ค.
ํด๋ก์ ์ค์ฝํ๋ฅผ ์ฐพ์์ ๊ณต๋ถํด๋ณด๊ธฐ
Control Flow
if(Truthy & Falsy) //true false๊ฐ ์๋๋ผ Truthy & Falsy๋
if(์ด ์์ ํ์คํ๊ฒ ์ฝ์ ์ ์๊ฒ ์ง๋๊ฒ ์ข๋ค. ๋ ๊ธธ๋ฉด ํจ์ ์ถ์ฒ)
function areValidNumbers(){};
if(areValidNumbers)
์ด๋ ๊ฒ ์งค๋์ ์ฅ์ ์ ๊ตณ์ด ๊ธด if๋ฌธ์ ์๋ณด๊ณ function ์ด๋ฆ๋ง ๋ณด๊ณ ๋ด์ฉ์ ์ ์ถํ๊ณ ๋์ด๊ฐ๋ ๋ ๋ ์ ์ฉํ๋ค.
var i = 0;
function init () {
console.log('me');
}
function isValid () {
console.log('you');
return i < 3;
}
funcrion update () {
console.log('we');
i++
}
for (init(); isValid(); update()){
console.log(i)
}
์ด๋ ๊ฒ ํ ๋ console.log์ ์ด๋ป๊ฒ ์ฐํ๊น? 1. me 2. you 3. 1 4. we 5. you 6. 2 7. we 8. you ์์
for (์ ์ผ ์ต์ด์ 1ํ์ฑ; ์กฐ๊ฑด; ์
๋ฐ์ดํธ)
var i = 0;
function init () {
console.log('me');
}
function isValid () {
console.log('you');
}
function foo () {
for (init(); isValid(); console.log('update')){
return;
}
}
foo();
์์ 1. me 2. you
var i = 0;
function init () {
console.log('me');
}
function isValid () {
console.log('you');
return i < 3;
}
function foo () {
for (init(); isValid(); console.log('update')){
return; //์ด๊ฒ๋ํ undefined๋ฅผ ๋ฆฌํดํ๋ค.
}
}
์์ 1. me 2. you 3. undefined
return์ return๊ตฌ๋ฌธ์ ์คํํ๊ณ ! ํจ์์ข ๋ฃ์ฐ!
break, continue๋ฅผ ์ฐพ์๋ณธ๋ค - loof์ ๊ด๋ จ๋๊ฑฐ, function์ด๋์ ์๊ด์๋ค
Last updated
Was this helpful?