JavaScript Variable Scope | Local scope Vs Global scope in JavaScript - JavaScript Tutorial 63

preview_player
Показать описание
Notes for You:: 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;
function display(){
var b=20;
}
display();

Example Code 2:
var a=10;
var b=30;
function display(){
var b=20;
}
display();

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

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

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

JavaScript Tutorials Playlist:-

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

jQuery Tutorials Playlist:-

jQuery UI Tutorials Playlist:-

Bootstrap Tutorials Playlist:-

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

► Subscribe to our YouTube channel:

► Visit our Website:

=========================================
Hash Tags:-
#ChidresTechTutorials #JavaScript #JavaScriptTutorial
Рекомендации по теме
Комментарии
Автор

SUBSCRIBE, SHARE & SUPPORT:
VISIT & LEARN AT FREE OF COST:

ChidresTechTutorials
Автор

sir with ur knowledge i am tying to do mind mapping sir.

many times i got confused related to function scope (local scope), global scope after watching ur video again and again i got one real example sir.

banana is global variable. it is available 365 days, mango is summer season fruit.we dont have chance to eat mango before and after summer, during summer season only we are having chance to eat mangoes.

in summer we can eat banana also (choice is ours)

banana is global variable, mango is local variable.

thank u sir. if ur sharing knowledge means we can do mind mapping and connecting to real things and easy to remember and also easy to explain in interviews with real examples.

thanks alot sir ur teaching skills vere level sir.

vamsikrishna
Автор

Great video as usual. Is there also a video about "closure"?
console.log("Thank You Sir!");

donxiqote
Автор

Sir i have a doubt.. please clarify me about this...
I have a code below which gives on clicking button for first time gives "This is Paragraph"....
But when i press for 2nd time, I am not getting "This is Paragraph".... again
Only for first time click it is working... if I want to get data as per clicks... then what to do.. please suggest me....

<html>
<body>
<input type="button" value="get" onclick="test()"/>
<p id="Demo"></p>
<script>
function test()
{
"This is Paragraph";
}
</script>
</body>
</html>

aravallivijay