Search⌘ K
AI Features

Using Operators with Different Types

Explore how JavaScript operators function with various variable types, including strings and null values. Learn about type coercion, where JavaScript converts types to perform operations, and understand the concept of NaN when invalid math occurs. This lesson helps you grasp key operator behaviors and type interactions in JavaScript.

Different Variable Types

We’ve shown these operators being used on numbers only. They can also be used with other variable types.

Node.js
let string1 = 'Hello ';
let string2 = 'there!';
console.log(string1 + string2); // -> Hello there!

String addition just joins the strings together into a new, larger string.

NaN

What happens if we try to use the other operators with strings? We get a ...

Ask