[JavaScript] Numbers
6382 ワード
Basic Operators
console.log(2 + 2);
console.log(4 - 2);
console.log(3 * 2);
console.log(6 / 2);
Exponentitation
Exponentitation is the process of taking quantity
b
(the base) to the power of another quantity e
(the exponent). Or in simpler words: it is the process of multiplying b
(the base) by itself as many times as indicated by e
(the exponent).console.log(2 ** 3); // => (2 * 2 * 2) result: 8
Modulo
Modulo (%) is the remainder operator.
// 4 / 2 = 2
console.log(4 / 2);
//With a remainder of 0
console.log(4 % 2);
// 7 / 2 = 3.5
console.log(7 / 2);
//With a remainder of 1
console.log(7 % 2);
// If a number modulus other number is equal to 0
// it is a multiple of "other number"
// 8 is indeed a multiple of 2!
console.log(8 % 2 === 0);
// 9 is NOT a multiple of 2!
console.log(9 % 2 === 0);
Assignment Operators Table
Operator Precedence
In mathematics and computer programming, the order of operations (or operator precedence) is a collection of rules that define which procedures to perform first to evaluate a given mathematical expression.
const i = 10 + (5 * 2 ** 3) / 4 - 6;
// === 10 + 5 * 8 / 4 - 6 <== start with the exponents (2 ** 3)
// === 10 + 5 * 2 - 6 <== then multiplication (5 * 8)
// === 10 + 10 - 6 <== then division (40 / 4)
// === 10 + 4 <== then addition (10 + 10 )
// ==> 14 <== and finally finish with subtraction (20 - 6)
Reference
この問題について([JavaScript] Numbers), 我々は、より多くの情報をここで見つけました https://velog.io/@tak_4242/JavaScript-Numbersテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol