Why don't we need quotations for numbers or booleans?

I have a question about using let as a variable. In one example, the value assigned to the variable after the = sign is put in quotes, and in other examples (the Boolean false and the number), no quotes were used. Is there an easy way to remember when quotes should be used and when they shouldn’t?

2 Likes

The quotes is used only with string argument, boolean and number don’t need it.
If you put quotes around a number, or boolean, it will be treated as a String

45 Likes

When declaring a variable using let and that variable being a number or a boolen, is quoatations not required?

Given quotation marks are for strings, so no

1 Like

We only use quotes (’’, “”) for strings. Not for numbers and boolean.

2 Likes

We don’t use let as a variable. We assign variables using let

4 Likes

Although both are primitive data types but symbols, numbers, boolean, null and undefined are all used without quotes (’ ').

Whereas, only string is used with quotes. For reference this information is available from from the very initial chapters of JS.

2 Likes

Just like numbers have their own identity like 4 and -4 are different from each other and mean different completely. The integers , symbols and etc are unique on their own. Boolean values like true and false convey their meaning as booleans when written in lowercase without any quotes…so in my understanding I told …

Hi,
I’ve just started with Codeacademy, so excited to be here.

This is my interpretation of quotes:

Whatever is given within quotes is taken literally as it appears. ‘Potatoe’ will be read as ‘Potatoe’. If it’s not in quotes, it has a function of some kind, like a keyword in JavaScript (like log) or if you have made Potatoe a variable and has a value, that value will be read. In the case of numbers, if it is in quotes, it will be read as a piece of text, the symbol itself with no value, so no calculations can be carried out with it. If a number is used with no quotes, the value of that number will be read and calculations may be carried out with it.

It’s like teaching a child to write the number 4 (the symbol), and later doing maths with it, 4 apples is the same as this many apples (draw 4 apples to show its value).

I suppose, in theory, you could assign the value -5.27 to the variable ‘8’, but I imagine this would not be best practice.

I hope this helps.

6 Likes

Thanks for clarifying - I thought quotes didn’t apply to numbers alone, not Boolean. :sweat_smile:

1 Like

Great analogy, thank you!

2 Likes

Not exactly. We use let, var and const to declare a variable. Value assignment is done with the assignment operator, which is represented by the = character. Except for const, variable assignment (and reassignment) can occur at a separate time, after declaration. Since const variables cannot be reassigned, a variable declared with const must be assigned at the moment of declaration.

3 Likes

This is a great explanation. Thanks for taking the time to detail your thought process.

1 Like