Numbers and maths · 숫자와 수학
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · 이 페이지는 최신 브라우저(SharedArrayBuffer 지원)가 필요합니다. Chrome, Edge, Firefox 또는 Safari를 최신 버전으로 업데이트해 주세요.
Maths like a calculator
- JavaScript does maths with
+-*/. - There is only one kind of number, so
/can give a decimal:7 / 2is3.5.
console.log(7 + 2); // → 9
console.log(7 / 2); // → 3.5
Remainder and powers
%gives the remainder after dividing:23 % 5is3(5 goes in 4 times, 3 left over).**raises to a power:2 ** 5is2 × 2 × 2 × 2 × 2.
console.log(23 % 5); // → 3
console.log(2 ** 5); // → 32
Order of operations
*/%happen before+and-— the same rules as in maths class.- Use brackets
( )to force what should happen first.
Explore · 탐색하기
Order of operations, step by step · 연산 순서, 단계별로
× and ÷ happen before + and −. Brackets go first of all. · ×과 ÷은 +과 −보다 먼저 발생합니다. 괄호는 가장 먼저 처리됩니다.
console.log(2 + 3 * 4); // → 14 (the 3 * 4 first)
console.log((2 + 3) * 4); // → 20 (the brackets first)
Common mistakes
%is the remainder operator;/can give a decimal."3" + 4gives"34"(a string), not7.
Now you try
- Use the maths operators.
- Press Check answer to test it.
Log 6 times 7 (it is 42). · 6 × 7을 로그(log)합니다 (结果是 42).
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.
Use % to log the remainder when 23 is divided by 5 (it is 3). · %을 사용하여 23을 5으로 나눈 나머지를 출력합니다(그 결과는 3입니다).
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.
a is 4 and b is 8. Log their average, (a + b) / 2 (it is 6). Use brackets so the addition happens first. · a은 4이고 b은 8입니다. 그들의 평균인 (a + b) / 2을 출력합니다(그 결과는 6입니다). 덧셈이 먼저 일어나도록 괄호를 사용하십시오.
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.