Variables in JS


How to do this?
"Use console.log to print out the length of the variable myCountry."


If you are on the lookout ....


google search
== the Book ==
javascript [your question]

== discussions / opinions ==
javascript [your question]

== guidance ==


You would have defined a variable myCountry
to which you assign a string Value
var myCountry = "tessa-land";

From now on,
if you use myCountry
the Javascript-interpreter will evaluate
the myCountry-variable to the string Value ="tessa-land"=

Javascript gives you a set of properties and pre-defined-functions/methods
under the String.prototype
Look in the left-hand column....
You will then have to follow the required-syntax...

With the console.log() method,
you are able to Display a result in the console which is in the right-hand-preview-screen.

console.log( myCountry.length );


Here's where I'm confused. If we declare the variable myCountry to be "tessa-land" & then subsequently console.log the length, why do we have to put the string value "tessa-land" in the parenthesis? Why wouldn't the JS recognize myCountry as tessa-land & put that in the parenthesis?

correct example:

var myCountry = "United States of America";
console.log("United States of America" .length );

why isn't it:

var myCountry = "United States of America";
console.log("myCountry" .length );

Maybe I'm thinking too much about SASS / SCSS & I'm missing something.
Is JS simply reading the string values inside the parenthesis & nothing else, not the machine name?
What's the point of declaring a var name if you have to put the full name when you call it up for a console.log?
I'm sure there's a million reasons & I haven't covered them yet.




If you define a variable using the var-keyword
and you assign a specific Value to this variable

The VALUE can be anything from:

•Object  ◦Function/'Method'

In our case that would be a string Value
var myCountry = "United States of America";


google search
=the book=
javascript variable,_variables,_and_literals