HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to JavaScriptVariables (let / const)Data TypesOperatorsStringsArraysObjectsConditions (if / else)Loops (for / while)FunctionsArrow Functions (=>)Array Methods (map / filter / reduce)
REFERENCE
📖 Overview
🖥️ Output & Console
📦 Variables
🔢 Numbers & Math
Math.round()Math.floor() / Math.ceil()Math.max() / Math.min()Math.random()Math.pow() / Math.sqrt()parseInt() / parseFloat()toFixed()
✍️ String
📋 Array
🗂️ Object
🔁 Condition & Loop
🧩 Function
🔄 Type & Conversion
JavaScript›REFERENCE›Numbers & Math
🔢

Numbers & Math

Numeric operations, rounding, and Math functions.

CommandDescription
Math.round()Rounds to the nearest integer.
Math.floor() / Math.ceil()Rounds down / up.
Math.max() / Math.min()Finds the maximum / minimum value.
Math.random()Generates a random decimal between 0 and 1.
Math.pow() / Math.sqrt()Exponents and square root.
parseInt() / parseFloat()Converts text to a number.
toFixed()Returns text with a specified decimal place.

Math.round()

Try it yourself →

Rounds to the nearest integer.

Syntax

Math.round(number)

Description

0.5 and above rounds up, below rounds down.

Returns

Rounded integer.

Example

console.log(Math.round(4.6));
console.log(Math.round(4.4));

Expected output

5
4

When to use?

Simplifying scores, averages, price displays.

Math.floor() / Math.ceil()

Try it yourself →

Rounds down / up.

Syntax

Math.floor(number) · Math.ceil(number)

Description

floor always rounds down, ceil always rounds up (regardless of the decimal).

Example

console.log(Math.floor(4.9));
console.log(Math.ceil(4.1));

Expected output

4
5

When to use?

Calculating page count, ceiling/floor limits.

Math.max() / Math.min()

Try it yourself →

Finds the maximum / minimum value.

Syntax

Math.max(a, b, ...) · Math.min(a, b, ...)

Description

Returns the largest or smallest number from the given numbers separated by commas. Use Math.max(...arr) for arrays.

Example

console.log(Math.max(3, 9, 5));
console.log(Math.min(...[4, 2, 7]));

Expected output

9
2

When to use?

Highest score, lowest price.

Math.random()

Try it yourself →

Generates a random decimal between 0 and 1.

Syntax

Math.random()

Description

Returns a random number between 0 (inclusive) and 1 (exclusive). Scale for a specific range: Math.floor(Math.random()*n).

Returns

Random decimal (0–1).

Example

const zar = Math.floor(Math.random() * 6) + 1;
console.log(zar >= 1 && zar <= 6);

Expected output

true

When to use?

Dice, random selection, games, shuffling.

Math.pow() / Math.sqrt()

Try it yourself →

Exponents and square root.

Syntax

Math.pow(base, exponent) · Math.sqrt(number)

Description

pow calculates powers (same as base ** exponent), sqrt gives the square root.

Example

console.log(Math.pow(2, 10));
console.log(Math.sqrt(144));

Expected output

1024
12

When to use?

Geometry, exponential growth, distance calculations.

parseInt() / parseFloat()

Try it yourself →

Converts text to a number.

Syntax

parseInt(text) · parseFloat(text)

Description

parseInt reads the integer at the beginning of the text, parseFloat reads the decimal. Returns NaN if it finds no number.

Returns

Number or NaN.

Example

console.log(parseInt("42 kalem"));
console.log(parseFloat("3.5kg"));

Expected output

42
3.5

When to use?

Converting form/input text to a number.

Common mistakes

  • ⚠️ parseInt("abc") → NaN; check the result before using it.

toFixed()

Try it yourself →

Returns text with a specified decimal place.

Syntax

number.toFixed(digits)

Description

Rounds the number to the given decimal places and returns it as TEXT (ideal for money display).

Returns

Formatted text (string).

Example

console.log((3.14159).toFixed(2));
console.log((5).toFixed(2));

Expected output

3.14
5.00

When to use?

Price/money display (always 2 decimal places).

Common mistakes

  • ⚠️ The result is TEXT; convert it back with Number() if you are going to use it in calculations again.
HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code