Curriculum
Course: JavaScript Basic
Login

Curriculum

JavaScript Basic

JSHome

0/216
Text lesson

Numeric Strings

Numeric values can be included within JavaScript strings.

let x = 100;         // x is a number

let y = “100”;       // y is a string

JavaScript attempts to convert strings to numbers in all numeric operations:

This will function correctly:

let x = “100”;
let y = “10”;
let z = x / y;

This will also function as intended:

let x = “100”;
let y = “10”;
let z = x * y;

And this will also function correctly:

let x = “100”;
let y = “10”;
let z = x – y;

However, this will not produce the desired result:

let x = “100”;
let y = “10”;
let z = x + y;

In the final example, JavaScript utilizes the + operator to concatenate the strings.