Skip to content

Instantly share code, notes, and snippets.

@rupeshtiwari
Created August 13, 2018 18:20
Show Gist options
  • Save rupeshtiwari/db6e2ce9c047005ef4561ed14b3b2f31 to your computer and use it in GitHub Desktop.
Save rupeshtiwari/db6e2ce9c047005ef4561ed14b3b2f31 to your computer and use it in GitHub Desktop.
What is scope in javascript
/**
* In JavaScript there are only 2 scopes, one is global scope and the other is Function scope.
* In Ecma Script 5 they have introduced 'let' variable which has lexical scope also.
*/
/*
* In below example log method has 2 things in scope one is global variable 'message' and the other is local variable 'prefix'
*/
var message = "hello world";
function log() {
var prefix = "Logger: ";
alert(prefix + message);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment