Saturday 22 December 2018

Is undefined a JavaScript keyword?

undefined is not a JavaScript keyword, it is a property of global object, i.e., it is a variable in global scope.

You can shadow the global property undefined in local scope.

HelloWorld.js
function print_me () {
    console.log(undefined)
    var undefined = "shadowed";
    console.log(undefined);
}

print_me();

Output
undefined
shadowed


Previous                                                 Next                                                 Home

No comments:

Post a Comment