When creating an object, one syntax you can use is the
new keyword on a function.
If you remove the word
new, it changes its meaning completely, and that’s because of how
new changes the meaning of
this refers to the global variable
window, representing the browser window. When you use
- a new Object is created
thisis assigned to the new Object in the scope of the function
- the return value of the function becomes the Object.
So if you removed the
new keyword, i.e.:
dog = undefined, and
window.sound = "Woof".