Fabio Sampaio Fabio Sampaio - 1 year ago 136
Javascript Question

Javascript "Equal Sequence" meaning

Sometimes in the internet I see a syntax that is strange to me. Something like:

console.log = console.error = console.info = console.debug = console.warn = console.trace = function() {}

How does this "equal" sequence work?


Answer Source

An assignment operator assigns a value to its left operand based on the value of its right operand.


a = b = c = d = 5;

The expression is resolved right to left so:

d = 5 and c = d (which is 5), b = c (5) and so on.

In your example those console methods are all being (re)defined as an empty function.

See: MDN: Assignment Operators for more info.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download