javascript define global variable
window.myGlobalVariable = "I am totally a global Var"; //define a global variable
var myOtherGlobalVariable="I too am global as long as I'm outside a function";
javascript define global variable
window.myGlobalVariable = "I am totally a global Var"; //define a global variable
var myOtherGlobalVariable="I too am global as long as I'm outside a function";
create global variable inside function JavaScript
<script>
function foo() {
window.yourGlobalVariable = ...;
}
</script>
global scope js
const color = 'blue'
const returnSkyColor = () => {
return color; // blue
};
console.log(returnSkyColor()); // blue
javascript global function
window.my_function = function(){
//
}
global variable in js
If you trying to acess a variable from a function
then,
let i=0;
function as(){
i=1 ///global variable
}
as()
console.log(i)
const d=()=>{
console.log("from d: ",i)
}
d()
the output
1
from d : 1
better way is window.myGlobalVariable = "your variable"
not encourged to use global variable at all
global variable in javascript
<script>
var yourGlobalVariable;
function foo() {
// ...
}
</script>
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us