Fabio Sampaio Fabio Sampaio - 13 days ago 6
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?

Thanks.

Answer

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

Consider:

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.