JavaScript Variable Scope - JavaScript Tutorial 63

Опубликовано: 05 Сентябрь 2017
на канале: ChidresTechTutorials
3,908
93

Notes for You:: JavaScript Variable Scope - JavaScript Tutorial 63
Local scope Vs Global scope in JavaScript.
Scope indicates the accessibility and visibility of variables.
JavaScript variables are of local scope (function scope) or global scope

Local scope:
Any variable declared inside a function is considered as in local scope
can be accessible only inside that function where it is declared
Local variables will be available only in the function execution
Local variables are created as soon as the control enters the function body and deleted as soon as the control exits the function body.

Global scope:
Any variable not declared inside a function is considered as in global scope
can be accessible anywhere in the script
Global variables will be available throughout the script execution


Example Code 1:
var a=10;
document.write("a= ", a, "<br/>"); // 10
function display(){
document.write("a= ", a,"<br/>"); // 10
var b=20;
document.write("b= ", b,"<br/>"); // 20
}
display();
document.write("b= ", b,"<br/>"); // error: b is not defined


Example Code 2:
var a=10;
document.write("a= ", a, "<br/>"); // 10
var b=30;
function display(){
document.write("a= ", a,"<br/>"); // 10
var b=20;
document.write("b= ", b,"<br/>"); // 20
}
display();
document.write("b= ", b,"<br/>");//30

Note:
replace < with less-than symbol.
replace > with greater-than symbol.

=========================================

Follow the link for next video:
JavaScript Tutorial 64 - Functions Vs. Call Stack in JavaScript
   • JavaScript Functions and the Call Sta...  

Follow the link for previous video:
JavaScript Tutorial 62 - IIFE ( Immediately Invoked Function Expression ) in JavaScript
   • JavaScript Immediately Invoked Functi...  

=========================================

JavaScript Tutorials Playlist:-
   • JavaScript Tutorials  

=========================================
Watch My Other Useful Tutorials:-

jQuery Tutorials Playlist:-
   • jQuery Tutorials  

jQuery UI Tutorials Playlist:-
   • jQuery UI Tutorials  

Bootstrap Tutorials Playlist:-
   • Bootstrap4 Tutorials  

=========================================

► Subscribe to our YouTube channel:
   / chidrestechtutorials  

► Visit our Website:
https://www.chidrestechtutorials.com

=========================================
Hash Tags:-
#ChidresTechTutorials #JavaScript #JavaScriptTutorial


На этой странице сайта вы можете посмотреть видео онлайн JavaScript Variable Scope - JavaScript Tutorial 63 длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь ChidresTechTutorials 05 Сентябрь 2017, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 3,908 раз и оно понравилось 93 зрителям. Приятного просмотра!