jquery - What is wrong with the scope of this variable? jsfiddle -


I'm stupid with this for a while and I'm not able to use variables painterspace In multiple tasks, I have simplified the code to read it easily.

Here's the bellow:

  jQuery (document) .ready (function ($) {var leaves = ''; $ (function () {var nav_height = $ ( ". Nav"). External high (); var leaves = nav_height - 10;}); // end function $ (".link_scroll"). (Function (event) {event.preventDefault ($); $ (' Results'). Html ('is wise:' + location of leaves);});});  

Why can not I use the location of the address

here

Leaves are within defined defined anonymous functions; You will not be able to use it outside the bracket

  {...}  

.

Use it inside an anonymous function - do not reboot it

  var parsaspeave = my_height - 10;  

Use instead

  leaves = my_height - 10;  

The reason for this is that in each circle, the interpreter will look in the symbol table object for a specific variable; If it has a declaration (var variableName) then it will create a new symbol table object unless it is present in any scope. When the radius is left out, all the objects will be removed from the symbol table. So only the variable with the lower position that the interputer knows about it, which has not yet been appointed.

Please tell me if you have any questions!


Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -