Tell us what’s happening:
I understand the lesson. I’ve passed the test. I just want to know if numbers ever need a quote. In this lesson, I was struggling at first because I kept putting my string in quotes (which is correct) and my number in quotes (which was not correct) which would prohibit me from moving on to the next lesson. Do numbers need quotes in any other situtation? Do you ever need quotes for numbers? Your code so far
// Only change code below this line
var myArray = ["James", 26];
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36.
Challenge: Store Multiple Values in one Variable using JavaScript Arrays
You put quotes around a number only when you want it to be part of a string, like "123 Maple Lane". Otherwise, you probably don’t want your number in quotes.
Oh ok. So if I had a array like this → var carTypes = ["Toyota 1994", "Ford"];
Then that is when those numbers would be in quotes?
versus if I have a array like this → var myAge = ["Jimmy", 26];
Then the number that is seperate from a string would NOT need to be in quotes ever?
Just being super ocd, i’m sorry. I know I shouldn’t be this literal and observant over something pretty self explanatory. I just am trying to instill it into my brain lol.
An important thing to remember is that a string is a string and number is a number, but a number in quotes is a string, and sometimes you want this, and other times you will realize JavaScript took the liberty of coercing your variables into data types you were not expecting and this can caused unwanted side effects . As an example:
let int = 1 + '2';
console.log(int) //12
console.log(typeof int) //string
The plus operator for two number such as 1 + 2 works as you would normally expect, but if use the plus operator with a string its going to concatenate the values so in the pervious example you had the number 1 and the string "2" so when you used the plus operator it concatenated them rather than adding them so you end up with the string "12"