ColdTree ColdTree - 1 month ago 6
Javascript Question

How to set a javascript var as undefined

Given:

console.log(boo); this outputs undefined


Given:

var boo = 1;
console.log(boo); this outputs 1


After defining boo and setting to 1, how can I then reset boo, so that console.log outputs undefined?

Thanks

Answer

delete boo

Don't use var boo = undefined. undefined is just a variable and if someone sets undefined = "hello" then you'll be getting hello everywhere :)

EDIT:

null wasn't same as undefined. removed that bit.