A string, also known as a text string, comprises a sequence of characters, such as “John Doe”.
Strings are enclosed within quotes, which can be either single or double quotes.
// Using double quotes: let carName1 = “Volvo XC60”; // Using single quotes: let carName2 = ‘Volvo XC60’; |
You can include quotes within a string, as long as they do not match the quotes used to delimit the string.
// Single quote inside double quotes: let answer1 = “It’s alright”; // Single quotes inside double quotes: let answer2 = “He is called ‘Johnny'”; // Double quotes inside single quotes: let answer3 = ‘He is called “Johnny”‘; |
All numbers in JavaScript are stored as decimal numbers, represented in floating-point format.
Numbers can be expressed with or without decimals.
// With decimals: // Without decimals: |
Very large or very small numbers can be represented using scientific (exponential) notation in JavaScript.
let y = 123e5; // 12300000
let z = 123e-5; // 0.00123