Operator in javascript

Something Like that:
Operator

What is Operator
A special function that is syntactically (written) Differently

For that you need to create first html code.

HTML

<p>Value of a =  <span id="demo1"></span></p>

After that add this JS code.

JS

var a = 4 + 3;
document.getElementById("demo1").innerHTML = a;

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

Now you can see

Value of a = 7


Now I want

var b = 4 + 3 * 5;
So what will be answer of b 35?

Wrong

It will be 19.

Why will it be 19?

Operator Precedence

Which Operator Function Gets Called first
* then +

JS

var b = 4 + 3 * 5;
document.getElementById("demo2").innerHTML = b;

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

Operator Precedence Table

Leave a Reply

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