Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

global scope js

const color = 'blue'

const returnSkyColor = () => {
  return color; // blue 
};

console.log(returnSkyColor()); // blue
Comment

global and function scope javascript

//This seems confusing, but if you understamd this, You are strong in hoisting
//this helps confusion b/w (gobal var, function's local var) & execution context

var a = 8; // global var has - 8

function A(){
	var a = 1;
	console.log(a); // 1
	function B(){
		var b = 3;
		a = 77; // replaces A()'s "a" value to 77 but (not the outer var a=8)
		console.log(a,b); // 77,3
		function C(){
			var a = 99;
			b = 1; //replaces "b" to outer B()func so B()'s "b" is 1 now
			c = 98; //globally available
			console.log(a,b,c); // 99,1,98
		}
	C();
	console.log(a,b,c); // 77,1,98
	}
B();
console.log(`a is : ${a}`); //77
};


console.log(`Initially 'a' is : ${a}`); //8
A();
console.log(`now 'a' is : ${a} - outer as global`); //8


//output
//global
	//8
//A
	//1
//B
	//77,3
//A
	//77
//C
	//99,1,98
	//77,1,98
//global
	//8 - outer global variable
Comment

PREVIOUS NEXT
Code Example
Javascript :: coreui react change background color 
Javascript :: navigation scroll react 
Javascript :: insert a string in another js 
Javascript :: webpack.config.js 
Javascript :: javascript add maxlength attribute 
Javascript :: sum function in javascript 
Javascript :: if event keycode and click 
Javascript :: before in javascript 
Javascript :: how to change the text of a paragraph 
Javascript :: jquery select 
Javascript :: npm modal 
Javascript :: create multiple buttons in javascript 
Javascript :: .keys() array 
Javascript :: js variable to string 
Javascript :: puppeteer stealth popup 
Javascript :: js filter text 
Javascript :: getdefaultmiddleware redux toolkit deprecated 
Javascript :: postman environment variable 
Javascript :: javascript fuzzy search 
Javascript :: react insert variable into string 
Javascript :: toastify js 
Javascript :: amcharts 
Javascript :: how to make a div auto refresh js 
Javascript :: js extract properties from object 
Javascript :: js round to x decimal places 
Javascript :: How to get random no. without math.random() function 
Javascript :: .push js 
Javascript :: css using inline styles 
Javascript :: js how to filter range in place 
Javascript :: listen to localstorage changes 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =