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

return์€ return ๋ฌธ๊ตฌ๋ฅผ ์‹คํ–‰์‹œํ‚ค๊ณ  function์„ ์ข…๋ฃŒ ์‹œํ‚จ๋‹ค.

ํด๋กœ์ € ์Šค์ฝ”ํ”„๋ฅผ ์ฐพ์•„์„œ ๊ณต๋ถ€ํ•ด๋ณด๊ธฐ

Control Flow

์ด๋ ‡๊ฒŒ ์งค๋•Œ์˜ ์žฅ์ ์€ ๊ตณ์ด ๊ธด if๋ฌธ์„ ์•ˆ๋ณด๊ณ  function ์ด๋ฆ„๋งŒ ๋ณด๊ณ  ๋‚ด์šฉ์„ ์œ ์ถ”ํ•˜๊ณ  ๋„˜์–ด๊ฐ€๋„ ๋ ๋•Œ ์œ ์šฉํ•˜๋‹ค.

์ด๋ ‡๊ฒŒ ํ• ๋•Œ console.log์—” ์–ด๋–ป๊ฒŒ ์ฐํž๊นŒ? 1. me 2. you 3. 1 4. we 5. you 6. 2 7. we 8. you ์˜ˆ์ƒ

์˜ˆ์ƒ 1. me 2. you

์˜ˆ์ƒ 1. me 2. you 3. undefined

return์€ return๊ตฌ๋ฌธ์„ ์‹คํ–‰ํ•˜๊ณ ! ํ•จ์ˆ˜์ข…๋ฃŒ์“ฐ!

break, continue๋ฅผ ์ฐพ์•„๋ณธ๋‹ค - loof์™€ ๊ด€๋ จ๋œ๊ฑฐ, function์ด๋ž‘์€ ์ƒ๊ด€์—†๋‹ค

Last updated

Was this helpful?