here i didn't understand what happen when i use var
before variable in function it give me different out put and with out using var
also i got a different output
here is a code that you can easily figure out whats going on
function value() {
var m = 8; //here i am using var as a datatype
console.log(m)
}
m = 7
console.log(m);
value();
console.log(m);
Function looks for the m
in the functional scope, if it does not find it there, it searches in the higher scope which over here is global scope.
In the first example, function creates a variable m
in the function scope and any update will be limited to the variable in the function. So, basically in this example there are 2 variables, with one m
belongs to the global scope and one m
belongs to the function scope. See the interpretation of code below.
var m;
function value() {
var m; // creates a variable m in the function scope
m = 8;
console.log(m)
}
m = 7
console.log(m);
value();
console.log(m);
Take a look at w3school's JavaScript Scope.
Below is example code of the difference of global variable and local variable.
function value() {
// local variable in value()
var m = 8;
console.log("in value() : " + m)
}
function value2() {
// set global variable as 9
m = 9;
console.log("in value2() : " + m)
}
// global variable
m = 7
console.log("before value() : " + m);
value();
console.log("after value() : " + m);
value2();
console.log("after value2() : " + m);
I am trying to use velocity together with jQuery (only for IE8 support) in an ES6 module. Consider this code: import { Component } from 'react'; import ReactDOM from 'react-dom'; import jquery from '...
I am trying to use velocity together with jQuery (only for IE8 support) in an ES6 module. Consider this code: import { Component } from 'react'; import ReactDOM from 'react-dom'; import jquery from '...
Firebase Cloud Messaging I have everything setup, the Push messages are received fine and when I click on it, it opens new window... but only in Chrome, in Firefox it is not opened. I have ...
Firebase Cloud Messaging I have everything setup, the Push messages are received fine and when I click on it, it opens new window... but only in Chrome, in Firefox it is not opened. I have ...
Why is my algorithm returning “-1” meaning that target value 73 isn’t in the array? (When clearly 73 is in the array). [this is from Khan Academy, but isn't helping] It's supposed to return either ...
Why is my algorithm returning “-1” meaning that target value 73 isn’t in the array? (When clearly 73 is in the array). [this is from Khan Academy, but isn't helping] It's supposed to return either ...
import React, { Component } from 'react' import Head from './Head' import Popular from './Popular' import Movie from './Movie' import Search from './Search' class Flix extends Component { ...
import React, { Component } from 'react' import Head from './Head' import Popular from './Popular' import Movie from './Movie' import Search from './Search' class Flix extends Component { ...