When creating an object, one syntax you can use is the new keyword on a function.

function Dog() = {
    this.sound = "Woof";
}

var dog = new Dog();

If you remove the word new, it changes its meaning completely, and that’s because of how new changes the meaning of this.

By default, this refers to the global variable window, representing the browser window. When you use new:

  • a new Object is created
  • this is 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.:

function Dog() = {
    this.sound = "Woof";
}

var dog = Dog();

dog = undefined, and window.sound = "Woof".