-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4 operators.js
More file actions
130 lines (105 loc) · 2.92 KB
/
4 operators.js
File metadata and controls
130 lines (105 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
JavaScript Arithmetic Operators
Arithmetic operators are used to perform arithmetic on numbers:
Operator Description
+ Addition
- Subtraction
* Multiplication
** Exponentiation (ES2016)
/ Division
% Modulus (Division Remainder)
++ Increment
-- Decrement
*/
let x = 5;
let y = 2;
let z = x + y;
console.log("x+y ",z);
z = x - y;
console.log("x-y ",z);
z = x * y;
console.log("x*y ",z);
z = x / y;
console.log("x/y ",z);
z = x ** y;
console.log("x**y ",z);
z = x % y;
console.log("x%y ",z);
z = --x + ++y;
console.log("--x + ++y ",z);
z = x++ + y--;
console.log("x++ + y-- ",z);
// ********Assignment operator*******
console.log(" *******Assignment operator******* \n")
let a=10;
let b=5;
a+=b;
console.log("a+=b ",a);
a-=b;
console.log("a-=b ",a);
a*=b;
console.log("a*=b ",a);
a/=b;
console.log("a/=b ",a);
a**=b;
console.log("a**=b ",a);
a%=b;
console.log("a%=b ",a);
/*
JavaScript String Operators
The + operator can also be used to add (concatenate) strings.
*/
console.log(" JavaScript String Operators\n")
let text1 = "John";
let text2 = "Doe";
let text3 = text1 + " " + text2;
console.log(text3);
text1 = "What a very ";
text1 += "nice day\n";
console.log(text1);
/*
*****************Adding Strings and Numbers*************
Adding two numbers, will return the sum, but adding a number and a string will return a string:
*/
x = 5 + 5;//10
y = "5" + 5;//55
z = "Hello" + 5;//Hello5
/*
***********JavaScript Comparison Operators***************
Operator Description
== 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
*/
/*
***********JavaScript Logical Operators**********
Operator Description
&& logical and
|| logical or
! logical not
*/
/*
*************JavaScript Type Operators*****************
Operator Description
typeof Returns the type of a variable
instanceof Returns true if an object is an instance of an object type
*/
/*
JavaScript Bitwise Operators
Bit operators work on 32 bits numbers.
Any numeric operand in the operation is converted into a 32 bit number. The result is converted back to a JavaScript number.
Operator Description Example Same as Result Decimal
& AND 5 & 1 0101 & 0001 0001 1
| OR 5 | 1 0101 | 0001 0101 5
~ NOT ~ 5 ~0101 1010 10
^ XOR 5 ^ 1 0101 ^ 0001 0100 4
<< Zero fill left shift 5 << 1 0101 << 1 1010 10
>> Signed right shift 5 >> 1 0101 >> 1 0010 2
>>> Zero fill right shift 5 >>> 1 0101 >>> 1 0010 2
*/