Home/Tutorials/JavaScript/Type Conversion and Equality

0 of 3 saved

JavaScript5 min read

Type Conversion and Equality

Read this chapter, write the program on this page, then pass a short check to open the next one.

== vs === and coercion.

Type Conversion and Equality

Always prefer === and !==. Loose == coerces types and surprises beginners.

  • === checks value and type.
  • Number("42") and String(42) convert explicitly.
  • Boolean("") is false; Boolean("0") is true.
console.log(1 === "1");
console.log(1 == "1");
console.log(Number("42"));

After you read this chapter, use Write (when available) and Quiz on this page to lock it in.