Consider following code snippet:
var var1 =12;
(function SelfExecutedTestFun(){
  console.log("value of var1 is:" + var1);
  var var2 = 500;
console.log("value of var1 from out side is:" + var1);
console.log("value of var2 from out side is:" + var2);
What will be printed to the console?
var1 is a global variable and it will print to the console:

value of var1 is: 12
value of var1 from out side is: 12

var2 variable is locked inside the function SelfExecuted scope and can not be accessed from the outside. Will print an error to console:

ReferenceError: var2 is not defined

@basimdev32 thanks for a feedback! can you tell, please, how did you achieve such result?

2018 Feb 4, 6:13:41 PM

Value of var2 from out side is:undefined

2018 Jan 28, 2:32:44 PM

@hopmaster checked! should be right answer

2017 Dec 6, 1:32:41 PM

value of var2 from out side is:undefined

2017 Jul 1, 7:41:58 PM

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Sign Up Now
or Subscribe for future quizzes