Commit afd9ae29 authored by MohammadAli Keshavarz's avatar MohammadAli Keshavarz

Operator precedence

parent 61f3bb77
...@@ -44,7 +44,7 @@ console.log(firstName + ' ' + lastName); ...@@ -44,7 +44,7 @@ console.log(firstName + ' ' + lastName);
/***************************** /*****************************
* Basic operators * Basic operators
*/ */
/*
var year, yearJohn, yearMark; var year, yearJohn, yearMark;
now = 2018; now = 2018;
ageJohn = 28; ageJohn = 28;
...@@ -65,3 +65,33 @@ console.log(typeof ageJohn); ...@@ -65,3 +65,33 @@ console.log(typeof ageJohn);
console.log(typeof 'Mark is older tha John'); console.log(typeof 'Mark is older tha John');
var x; var x;
console.log(typeof x); console.log(typeof x);
*/
/*****************************
* Operator precedence
*/
var now = 2018;
var yearJohn = 1989;
var fullAge = 18;
// Multiple operators
var isFullAge = now - yearJohn >= fullAge; // true
console.log(isFullAge);
// Grouping
var ageJohn = now - yearJohn;
var ageMark = 35;
var average = (ageJohn + ageMark) / 2;
console.log(average);
// Multiple assignments
var x, y;
x = y = (3 + 5) * 4 - 6; // 8 * 4 - 6 // 32 - 6 // 26
console.log(x, y);
// More operators
x *= 2;
console.log(x);
x += 10;
console.log(x);
x--;
console.log(x);
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment