Mohan Gupta
What are global variables in javascript?
By Mohan Gupta in JavaScript on May 08 2013
  • Bidyasagar Mishra
    Jul, 2019 17

    outside the function decalred variable is known as global variables

    • 0
  • Praveen Dhatrika
    Jun, 2015 3

    Global variables are the variables declared outside a function. Global variables have global scope meaning all scripts and functions on the page can access them. The lifetime of a global variable starts with it's declaration and is deleted when the page is closed.Also, If you assign a value to a variable that has not been declared, it will automatically become a global variable, even if it is present inside a function.function GlobalEx() {// The variable greeting is not declared but a value is assigned.// So it will automatically become a global variablegreeting = "JavaScript Global variable example"; }GlobalEx();// Variable greeting is available outside the functionalert(greeting);

    • 0
  • Amit Tripathi
    Jul, 2014 25

    Hi Mohan ,var iAmGlobal = "some val"; //Global variable declaration//Any place in other part of codefunction doSomething() {//iAmGlobal = "changed value";alert(iAmGlobal); //I am accessible here too !! }

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS