Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

var hoisting.js

var defaultname = "John";
var name = "rayn";

function doit() {
  if(!name){
   		var name = defaultname;
  }
  return name;
}

var ourname = doit();
console.log(ourname); //John
// because name inside function will have more priority over outside name variable. 
// And, this inside name variable will be declared in memory as undefined due to hoisting.
Source by www.tutorialspoint.com #
 
PREVIOUS NEXT
Tagged: #var
ADD COMMENT
Topic
Name
3+1 =