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
✍️ String
📋 Array
🗂️ Object
🔁 Condition & Loop
🧩 Function
🔄 Type & Conversion
Number()String()Boolean() / truthy== vs ===
JavaScript›REFERENCE›Type & Conversion
🔄

Type & Conversion

Type conversion and equality check.

CommandDescription
Number()Converts the value to a number.
String()Converts the value to text.
Boolean() / truthyBoolean value (true/false).
== vs ===Equality check: === is preferred.

Number()

Try it yourself →

Converts the value to a number.

Syntax

Number(value)

Description

Converts the text to a number. Returns NaN if it cannot be converted. Unlike parseInt: the entire text must be a number.

Returns

Number or NaN.

Example

console.log(Number("42") + 8);
console.log(Number("3.5") * 2);

Expected output

50
7

When to use?

Ignore the input text.

Common mistakes

  • ⚠️ Number("12x") → NaN (whereas parseInt gives 12).

String()

Try it yourself →

Converts the value to text.

Syntax

String(value)

Description

Converts values like numbers and arrays to text (or use template literals).

Returns

Text (string).

Example

console.log(String(36) + " age");
console.log((36).toString());

Expected output

36 age
36

When to use?

Concatenating numbers with text, formatting.

Boolean() / truthy

Try it yourself →

Boolean value (true/false).

Syntax

Boolean(value)

Description

0, '' (empty text), null, undefined, NaN are considered 'falsy' (counted as false); everything else is 'truthy'. Used automatically in conditions.

Example

console.log(Boolean(0));
console.log(Boolean("text"));
console.log(Boolean(""));

Expected output

false
true
false

When to use?

Checking 'is it empty or filled': if (text) { ... }.

== vs ===

Try it yourself →

Equality check: === is preferred.

Syntax

a === b

Description

== performs type conversion before comparison (can be confusing); === checks for both value and type equality. Always use ===.

Example

console.log(5 == "5");
console.log(5 === "5");

Expected output

true
false

When to use?

Safe comparison.

Common mistakes

  • ⚠️ == leads to quirks like 0 == "" or 1 == true; === prevents these.
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