It’s declared inside a closure, which means it can only be accessed there. If you want a variable accessible globally, you can remove the var
:
$(function(){
value = "10";
});
value; // "10"
This is equivalent to writing window.value = "10";
.
More Related Contents:
- What is the scope of variables in JavaScript?
- How do JavaScript closures work?
- JavaScript check if variable exists (is defined/initialized)
- How can I determine if a variable is ‘undefined’ or ‘null’?
- Static variables in JavaScript
- Convert string to variable name in JavaScript
- Javascript Regex: How to put a variable inside a regular expression? [duplicate]
- How to check a not-defined variable in JavaScript
- JavaScript variable definition: Commas vs. Semicolons
- JavaScript check if variable exists (is defined/initialized)
- “Variable” variables in JavaScript
- Pass vars to JavaScript via the SRC attribute
- What does variable declaration with multiple comma separated values mean (e.g. var a = b,c,d;)
- javascript pass object as reference
- Variables set during $.getJSON function only accessible within function
- how to access object property using variable [duplicate]
- Is there a better way of writing v = (v == 0 ? 1 : 0); [closed]
- Redeclaring a javascript variable
- javascript variable scope in the IF statement
- When/why to prefix variables with “$” when using jQuery? [duplicate]
- How can I make a program wait for a variable change in javascript?
- Variable re-assignment of object reference leaves other object unaltered (no “transitive” assignment)
- What does [] mean in JavaScript?
- How to access a JavaScript variable from code behind in asp.net
- Why does accessing a non-existent object property result in `undefined` instead of throwing a `ReferenceError`?
- JSON to string variable dump
- When to use var in Javascript [duplicate]
- What is the best method to convert floating point to an integer in JavaScript?
- Get all Javascript Variables?
- Print / display a JavaScript variable’s name instead of it’s value