Skip to content

Operators : JS

Marie-Louise edited this page Jan 17, 2019 · 4 revisions

Math operators

now = 2018;
ageJohn = 28;
ageMark = 33;

console.log(ageJohn);
console.log(now + 2);
console.log(now * 2);
console.log(now / 10);

Logical operators

var johnOlder = ageJohn < ageMark;
console.log(johnOlder);

typeof operators

console.log(typeof johnOlder);
console.log(typeof ageJohn);
console.log(typeof 'Mark is older than John');

operator precedence

which means, which operator is executed first

var now = 2018;
var yearJohn = 1989;

in this line the - gets executed first, then >= and then = is last.

var isFullAge = now - yearJohn >= fullAge; //true

console.log(isFullAge);

in the line below the grouping (..) will take the highest precedent so will be executed first. var average = (ageJohn + ageMark) / 2;

operator precedence MDN

Clone this wiki locally