javascript operators
&& logical and
|| logical or
! logical not
javascript operators
&& logical and
|| logical or
! logical not
javascript operators
= assignment operator
var x = 2
+ addition operator
2 + 3 = 5
- subtraction operator
2 - 3 = -1
* multiplicative operator
2 * 3 = 6
/ division operator
3 / 2 = 1.5
% modulus operator
3 % 2 = 1
++ increment operator
var x = 2
x++
// x now equals 3 (x = x + 1 in literal notation)
-- decrement operator
var x = 3
x--
// x now equals 2 (x = x - 1 in literal notation)
+= additive reassignment operator
var x = 2
x += 3
// x now equals 5 (x = x + 3 in literal notation)
-= subtractive reassignment operator
var x = 3
x -= 2
// x now equals 1 (x = x - 2 in literal notation)
*= multiplicative reassignment operator
var x = 3
x *= 2
// x now equals 6 (x = x * 2 in literal notation)
/= division reassignment operator
x = 3
x /= 2
// x now equals 1.5 (x = x / 2 in literal notation)
%= modulus reassignment operator
x = 3
x %= 2
// x now equals 1 (x = x % 2 in literal notation)
== logical comparison operator
2 == 2 // Returns true
2 == "2" // Returns true
2 == 3 // Returns false
=== logical strict comparison operator
2 === 2 // Returns true
2 === "2" // Returns false
2 === 3 // Returns false
!= logical not equal comparison operator
2 != 3 // Returns true
2 != 2 // Returns false
2 != "2" // Returns false
!== logical not equal strict comparison operator
2 !== 3 // Returns true
2 !== 2 // Returns false
2 !== "2" // Returns true
< logical less than comparison operator
2 < 3 // Returns true
3 < 2 // Returns false
> logical greater than comparison operator
3 > 2 // Returns true
2 > 3 // Returns false
3 > 3 // Returns false
<= logical less than or equal to comparison operator
2 <= 3 // Returns true
3 <= 3 // Returns true
3 <= 2 // Returns false
>= logical less than or equal to comparison operator
3 >= 2 // Returns true
3 >= 3 // Returns true
2 >= 3 // Returns false
|| logical or operator
x = 3
(x == 3 || x == 2) // Returns true
(x == 2 || x == 1) // Returns false
&& logical and operator
x = 2
y = 3
(x == 2 && y == 3) // Returns true
(x == 2 && y == 4) // Returns false
or operator in javascript
//The OR operator in Javascript is 2 verticals lines: ||
var a = true;
var b = false;
if(a || b) {
//one of them is true, code inside this block will be executed
}
javascript operators
== equal to
=== equal value and equal type
!= not equal
!== not equal value or not equal type
> greater than
< less than
>= greater than or equal to
<= less than or equal to
? ternary operator
... in javascript
function sum(x, y, z) {
return x + y + z;
}
const numbers = [1, 2, 3];
console.log(sum(...numbers));
// expected output: 6
console.log(sum.apply(null, numbers));
// expected output: 6
/* Spread syntax (...) allows an iterable such as an array expression or string
to be expanded in places where zero or more arguments (for function calls)
or elements (for array literals) are expected, or an object expression to be
expanded in places where zero or more key-value pairs (for object literals)
are expected. */
// ... can also be used in place of `arguments`
// For example, this function will add up all the arguments you give to it
function sum(...numbers) {
let sum = 0;
for (const number of numbers)
sum += number;
return sum;
}
console.log(sum(1, 2, 3, 4, 5));
// Expected output: 15
// They can also be used together, but the ... must be at the end
console.log(sum(4, 5, ...numbers));
// Expected output: 15
operators in javascript
// Javascript Airthmetic Operators
+ : Addition
- : Subtraction
* : Multiplication
** : Exponentiation (ES2016)
/ : Division
% : Modulus (Division Remainder)
++ : Increment
-- : Decrement
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us