showing results for - "operators in javascript"
Beatrice
20 Jul 2017
1&&	logical and
2||	logical or
3!	logical not
Alessio
09 Nov 2018
1==	equal to
2===	equal value and equal type
3!=	not equal
4!==	not equal value or not equal type
5>	greater than
6<	less than
7>=	greater than or equal to
8<=	less than or equal to
9?	ternary operator
Salvatore
27 Feb 2016
1=  assignment operator 
2var x = 2
3
4
5+  addition operator
62 + 3 = 5
7
8
9-  subtraction operator
102 - 3 = -1
11
12
13*  multiplicative operator
142 * 3 = 6
15
16
17/  division operator
183 / 2 = 1.5
19
20
21%  modulus operator
223 % 2 = 1
23
24
25++  increment operator
26var x = 2
27x++
28// x now equals 3 (x = x + 1 in literal notation)
29
30
31--  decrement operator
32var x = 3
33x--
34// x now equals 2 (x = x - 1 in literal notation)
35
36
37+=  additive reassignment operator
38var x = 2
39x += 3
40// x now equals 5 (x = x + 3 in literal notation)
41
42
43-=  subtractive reassignment operator
44var x = 3
45x -= 2
46// x now equals 1 (x = x - 2 in literal notation)
47
48
49*=  multiplicative reassignment operator
50var x = 3
51x *= 2
52// x now equals 6 (x = x * 2 in literal notation)
53
54
55/=  division reassignment operator
56x = 3
57x /= 2
58// x now equals 1.5 (x = x / 2 in literal notation)
59
60
61%=  modulus reassignment operator
62x = 3
63x %= 2
64// x now equals 1 (x = x % 2 in literal notation)
65
66
67==  logical comparison operator
682 == 2 // Returns true
692 == "2" // Returns true
702 == 3 // Returns false
71
72
73===  logical strict comparison operator
742 === 2 // Returns true
752 === "2" // Returns false
762 === 3 // Returns false
77
78
79!=  logical not equal comparison operator
802 != 3 // Returns true
812 != 2 // Returns false
822 != "2" // Returns false
83
84
85!==  logical not equal strict comparison operator
862 !== 3 // Returns true
872 !== 2 // Returns false
882 !== "2" // Returns true
89
90
91<  logical less than comparison operator
922 < 3 // Returns true
933 < 2 // Returns false
94
95
96>  logical greater than comparison operator
973 > 2 // Returns true
982 > 3 // Returns false
993 > 3 // Returns false
100
101
102<=  logical less than or equal to comparison operator
1032 <= 3 // Returns true
1043 <= 3 // Returns true
1053 <= 2 // Returns false
106
107
108>= logical less than or equal to comparison operator
1093 >= 2 // Returns true
1103 >= 3 // Returns true
1112 >= 3 // Returns false
112
113
114|| logical or operator
115x = 3
116(x == 3 || x == 2) // Returns true
117(x == 2 || x == 1) // Returns false
118
119
120&& logical and operator
121x = 2
122y = 3
123(x == 2 && y == 3) // Returns true
124(x == 2 && y == 4) // Returns false
Roberto
28 Jun 2017
1function sum(x, y, z) {
2  return x + y + z;
3}
4
5const numbers = [1, 2, 3];
6
7console.log(sum(...numbers));
8// expected output: 6
9
10console.log(sum.apply(null, numbers));
11// expected output: 6
12
13/* Spread syntax (...) allows an iterable such as an array expression or string 
14to be expanded in places where zero or more arguments (for function calls) 
15or elements (for array literals) are expected, or an object expression to be 
16expanded in places where zero or more key-value pairs (for object literals) 
17are expected. */
18
19// ... can also be used in place of `arguments`
20// For example, this function will add up all the arguments you give to it
21function sum(...numbers) {
22  let sum = 0;
23  for (const number of numbers)
24    sum += number;
25  return sum;
26}
27
28console.log(sum(1, 2, 3, 4, 5));
29// Expected output: 15
30
31// They can also be used together, but the ... must be at the end
32console.log(sum(4, 5, ...numbers));
33// Expected output: 15
34
Yannick
23 Jul 2016
1//&& returns true if both values are true
2//or returns the second argument if the first is true
3var a = true
4var b = ""
5var c = 1
6
7true && "" //""
8"" && 1 //""
9false && 5 //false
Daniele
09 Oct 2017
1// Javascript Airthmetic Operators
2+	:   Addition
3-	:   Subtraction
4*	:   Multiplication
5**	:   Exponentiation (ES2016)
6/	:   Division
7%	:   Modulus (Division Remainder)
8++	:   Increment
9--	:   Decrement
similar questions
queries leading to this page
operators in javascript