Bhavya Dhiman
Bhavya Dhiman

Reputation: 30

undefined when declared as a variable name throws error in browser but runs successfully when runs in node.js

I tried to execute following lines of code on Nodejs and chrome browser. In nodejs, it executed successfully But on chrome browser, it throws an error.

const undefined = 1;
console.log(undefined); 
// Nodejs: prints 1
//chrome browser: VM359:1 Uncaught SyntaxError: Identifier 'undefined' has already been declared

If undefined is already declared as a value, don't you guys think undefined is behaving a variable in nodejs ?

Upvotes: 0

Views: 44

Answers (1)

SkorpEN
SkorpEN

Reputation: 2709

You can not override undefined according to https://stackoverflow.com/a/7173833/1331578 . It might work on node where no global object will be used. But in general it is just not writable name.

Upvotes: 1

Related Questions