01 / 05
A number is not wrapped in "
The basics of syntax
INPUT · Slides
01 / 05
When you want a number, you write it as it is — no " around it.
Leave it bare and JS understands "this is a number".
console.log(42);Result
42
02 / 05
"42" and 42 look identical on the screen, but inside JS they are two different things.
"42" … text (we call it a string)42 … a numberSame look, different handling. This is one of the first places people trip up.
console.log("42");console.log(42);Result
42 42
03 / 05
A number can be worked out. A string cannot.
Wrap it in " and it stops being a sum — it becomes just some characters.
console.log(3 + 5);console.log("3 + 5");Result
8 3 + 5
04 / 05
A phone number or a postcode looks like a number, but you normally hold it as a string.
As a number the leading 0 disappears, and you are never going to add it to anything anyway.
The question is not "does it look like digits" but "am I going to do maths with it".
console.log(0123);console.log("0123");Result
83 0123
05 / 05
When you are not sure, think of it this way.
")These two come up again and again from here on. When you hunt down an error, the first thing you will check is "is this a string or a number".
Let us get the difference into your fingers.