Understand numeric calculations, modulo remainders, divisibility checks, integer arithmetic, and IEEE-754 double precision floating point rules.
Learn how variables act as labeled containers for data using const, let, and var to manage lexical scope and reassignment safely in modern applications.
Unlike languages with separate int and float types, JavaScript uses a single primitive number type (64-bit double precision floating point) for both integers and decimal numbers.
Beyond standard addition (+), subtraction (-), multiplication (*), and division (/), the modulo operator (%) is a fundamental tool for checking number divisibility, determining even/odd states, and cycling indices in round-robin loops.
The modulo operator returns the remainder left over when one integer is divided by another:
const remainder = 10 % 3;
console.log(remainder); // 1 (10 divided by 3 is 3, with 1 left over)
// Checking if a number is even or odd
function isEven(num) {
return num % 2 === 0;
}
console.log(isEven(4)); // true
console.log(isEven(7)); // false
JavaScript provides a built-in Math object for common mathematical operations:
console.log(Math.round(4.7)); // 5 (Round to nearest integer)
console.log(Math.floor(4.9)); // 4 (Round down)
console.log(Math.ceil(4.1)); // 5 (Round up)
console.log(Math.max(10, 20, 5)); // 20
console.log(Math.min(10, 20, 5)); // 5
0.1 + 0.2): Because computers store numbers in binary (base-2), fractional decimals cannot always be represented with exact precision. In JavaScript, 0.1 + 0.2 evaluates to 0.30000000000000004. For monetary/currency calculations, always work in whole cents before converting to dollars!NaN: Operations like "hello" * 5 return NaN. NaN is the only value in JavaScript that is NOT equal to itself (NaN === NaN is false!). Use Number.isNaN(val) to check for invalid numbers.Use % whenever you need to check divisibility or cyclical limits. Next, let's explore how boolean logic drives application decision making!