Associativity in javascript

Something Like that:
Associativity

What is Associativity
what order Operator function get called in – left to right or right to left.

For that you need to create first html code.

HTML

<p>Value of a =  <span id="demo1"></span></p>
<p>Value of b =  <span id="demo2"></span></p>
<p>Value of c =  <span id="demo3"></span></p>

After that add this JS code.

JS

var a = 2, b = 3, c = 4;
a = b = c;

document.getElementById("demo1").innerHTML = a;
document.getElementById("demo2").innerHTML = b;
document.getElementById("demo3").innerHTML = c;

[codepen_embed height=”265″ theme_id=”0″ slug_hash=”xLVbwX” default_tab=”result” user=”pradeepanvi”]See the Pen Associativity in javascript by Pradeep Kumar (@pradeepanvi) on CodePen.[/codepen_embed]

Now you can see

Value of a = 4
Value of b = 4
Value of c = 4

You can see all of showing 4.

Why it is?
Due to Associativity

For more detail check Operator Lecture

Leave a Reply

Your email address will not be published. Required fields are marked *