Javascript Function Global Object In Browser

Description

Javascript Function Global Object In Browser

View in separate window


<html>
<!-- Demonstrating the nature of the global and window objects -->
<head></head>
<body>
<script>

let mylet = "Hello";

function checkVars1() {//from   w  w  w .  j  a v  a 2  s. c o  m
    console.log("checkVars1: Checking myVar: " + mylet);  // "Hello"
}

function checkVars2() {
    let mylet = "World";
    console.log("checkVars2: Checking myVar: " + mylet); // "World"
    console.log("checkVars2: Checking window.myVar: " + window.mylet);  // "Hello"
}

checkVars1();
checkVars2();

</script>
</body>
</html>



PreviousNext

Related