JavaScriptμμλ μ«μ λ°μ΄ν°νμ κ³Ό μν ννμμ μ¬μ©ν΄μ κ³μ°μ ν μ μλ€.
let a = 3.3;
let b = 1;
let c = -30;
let ex1 = a + b;
let ex2 = b * c / 10;
let ex3 = a + 10;
let ex4 = c - b;
let ex5 = a + 10 * b * b / 2 + 3;
ex λ³μλ€μ μ μΈν λ³μλ€λ‘ μνμμ μ μ₯ν΄λμλ€. μ΄κ²λ€μ console.log ν¨μλ₯Ό μ΄μ©ν΄ μΆλ ₯νμ λ μ΄λ€ κ²°κ³Όκ°μ΄ λμ€κ² λ κΉ?
κ²°κ³Ό :
ex1 : 4.3
ex2 : -3
ex3 : 13.3
ex4 : 31
ex5 : 11.3
+, -, /, * μ°μ°μ μΌμμνμμ μΉμν μν ννμμ΄λ€. μ΄ μΈμλ μ»΄ν¨ν° μΈμ΄μμ μ¬μ©λλ μν ννμμ΄ λ μλλ° λ°λ‘ μ¦κ° μ°μ°μ(++, --)μ΄λ€.
let num = 10;
num++;
κ²°κ³Ό:
11
10μ΄ λ΄κ²¨μλ λ³μ numλ₯Ό μ°μ°μλ₯Ό μ¬μ©ν ν μΆλ ₯νλ©΄ κ²°κ³Όλ 11μ΄ λμ¨λ€. μ΄μ²λΌ μ°μ°μ ++μ ν΄λΉ λ³μμ 1μ μ¦κ°μμΌμ€λ€.
let num = 10;
num--;
κ²°κ³Ό:
9
λ°λλ‘ --λ₯Ό μ¬μ©νλ©΄ 1μ κ°μμμΌμ£Όλ©° κ²°κ³Όκ°μ 10μμ 1μ κ°μμν¨ κ²°κ³ΌμΈ 9κ° λμ€κ² λλ€.
μ¦κ° μ°μ°μλ μμ λΆλλ λ€μ λΆλλμ λ°λΌ κ²°κ³Όκ° λ¬λΌμ§ μ μλ€.
λ³μ μμ μ€λ κ²½μ°
: μ¦κ°λ κ°μ μ°μ°μ μ°μ μ μΌλ‘ μννλ€.λ³μ λ€μ λΆλ κ²½μ°
: μμ μμ
μ λ€ λ§μΉ λ€ μ¦κ°λ κ°μ μ°μ°μ μννλ€.let num = 1;
let newNum = num++;
console.log(num);
console.log(newNum);
κ²°κ³Ό:
num : 2
newNum : 1
μ μ΄λ° κ²°κ³Όκ° λμ€κ² λ κΉ? κ°μ΄ 1μΈ num λ³μκ° μκ³ , newNumμλ num++μ ν λΉνλ€.
num++μ νμ μ°μ°μμ΄λ€. μ¦, μμ κ³Όμ μ λ€ λ§μΉ λ€μ 1μ μ¦κ°μν¨λ€. let newNum = num++;
μ νμ΄μ μ¨λ³΄λ©΄
let num = 1;
let newNum = num;
num = num + 1;
++μ΄ λΆλ μμΉλ₯Ό μμΌλ‘ νμ λλ μ΄λ€ κ²°κ³Όκ° λμ¬κΉ?
let num = 1;
let newNum = ++num;
console.log(num);
console.log(newNum);
κ²°κ³Ό:
num : 2
newNum : 2
++μ΄ μμ λΆμΌλ©΄ λ¨Όμ μ¦κ°μν€κ±°λ κ°μμν¨ λ€μ λ³μμ κ°μ ν λΉνλ―λ‘
let num = 1;
num = num + 1;
let newNum = num;