Javascript used of quotations


#1

Trying to figure the difference of when to use quotations. For example:

For this tutorial with console.log we used quotations

console.log("January".substring(0,3));
console.log("Melbourne is great".substring(0,12));
console.log("Hamburgers".substring(3,10));

But here, after console.log the use of quotations would make these codes invalid. How come?

var myCountry = "United States";

console.log(myCountry.length);

console.log(myCountry.substring(0,3));


#2

We use quotation marks when we are wanting to make a string.

var myCountry = "United States";

console.log(myCountry.length);

console.log(myCountry.substring(0,3));

If you used quotation marks here like this.

console.log("myCountry".substring(0,3));

It would console.log the word "myCountry" rather than the value of the variable myCountry.

Let me know if that helped or if you need further explanation.


#3

That makes a great deal of sense now. Thanks for replying!


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.