Q:

Why does a variable assignment not throw a ReferenceError when the variable is not defined - JavaScript

I've tried this in Chrome, Opera, Microsoft Edge, Internet Explorer and Mozilla Firefox and still gotten the same case: A ReferenceError exception is not thrown that the variable I assigned a value is not defined.

The syntax is:
// Where `identifier_name` was not formally declared/ initialized.
(function() {})(identifier_name = 2)

Why does this behavior occur?
Edit: Just to add, this doesn't work if what is being assigned is a property of an object i.e.:
// Throws a ReferenceError that `object_name` is not defined.
(function() {})(object_name.property_name = 2)

A:

Thats what we used to call the horror of implicit globals
You basically create a global variable by accident. You can "use strict";mode to prevent that.
Your second snippet does not work because you are trying to access a variable that was not declared yet, which is different from assigning to a variable that was not declared already (cause that implicitly declares the variable).

