Example creating Global variable:-

Global variable: A variable which can be variable from any where of the page.

Following are different two ways.

First Way Declare the JavaScript variable at the top of JavaScript code and out of function & objects.

var globalVariable1 ='This is global variable 1'

Second Way Declare a varaible without "var" in Function.

function testfunction(){
    globalVariable2 ='This is global variable 2'
}

results matching ""

    No results matching ""