What is it called when you pass a string literal to a variable, then
assign data from that string to a new variable like so?
Not sure why I am having trouble finding more information on this syntax
but it goes like so...
var str = "Hello", length = str.length;
console.log(length); //5
Let me go into what I am doing so the answer can be relevant. I can keep
assigning like so...
var str = "Hello", length = str.length, lengthtwo = str.length*2;
console.log(length); //5
console.log(lengthtwo); //10
Now I attempted to test local scope...
(function() {var str = "Hello", length = str.length, var lengthtwo =
str.length*2;})();
And I get a "SyntaxError: Unexpected token var", but if I use...
(function() {var str = "Hello", length = str.length, lengthtwo =
str.length*2;})();
console.log(length); //5
console.log(lengthtwo); //10
It looks to be creating a global variable, but you can not create a local.
Looks like issues with not wrapping in a function, a block or method
(whatever the rules are). I simply want to find what to search for, so I
can find topics on this syntax. Are we trying to understand Objects, or is
this a feature falling under functional programming? Sorry, I am going
through a tutorial marathon right now, and this one has me stuck.
Also, I get you can do...
var foo = 1,
bar = 2;
That would create two local scope variables as the var is passed to bar as
well. So if I use a similar scope test on this one I get not defined,
unlike the previous test.
No comments:
Post a Comment