0

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 ?

Bhavya Dhiman
  • 282
  • 2
  • 15
  • 1
    See https://stackoverflow.com/questions/36519946/what-happens-if-we-set-the-value-of-undefined for an explanation – sangeeth96 Jan 22 '20 at 17:59

1 Answers1

1

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.

SkorpEN
  • 2,491
  • 1
  • 22
  • 28