Warning: count(): Parameter must be an array or an object that implements Countable in /customers/d/f/8/sveitech.dk/httpd.www/wp-content/plugins/css-javascript-toolbox/framework/events/subjects/hook.subject.php on line 81 Warning: count(): Parameter must be an array or an object that implements Countable in /customers/d/f/8/sveitech.dk/httpd.www/wp-content/plugins/css-javascript-toolbox/framework/events/subjects/hook.subject.php on line 82 Warning: count(): Parameter must be an array or an object that implements Countable in /customers/d/f/8/sveitech.dk/httpd.www/wp-content/plugins/css-javascript-toolbox/framework/events/subjects/hook.subject.php on line 81 Warning: count(): Parameter must be an array or an object that implements Countable in /customers/d/f/8/sveitech.dk/httpd.www/wp-content/plugins/css-javascript-toolbox/framework/events/subjects/hook.subject.php on line 82 Javascript Language | Sveitech

Javascript Language

Scope

Javascript does not have block-scope like C++ or Java for example. The only scope that exists within Javascript, is function scope.


var_1 = 100; // global scope variable
local var_2 = 200; // global scope variable

function foo() {
var gizmo_1 = "hello"; // local to foo-function scope
gizmo_2 = 200; // global scope, because var keyword is not used.
}

for(var i = 0; i < 10; i++) { // blocks does not have scope. i variable is in // global scope. var something_1 = []; // still a global variable. No scope in blocks. } [/js] The global scope may be different things depending on the execution environment. In a browser, the global scope is usually the document object. In nodejs, the global scope can be a module, or the top-level GLOBAL object.

Arrays

Sveistrup Technologies