1.Assignment operators
var x = 5;
var y = 5;
2.Arithmetic operators
An arithmetic operator takes numerical values (either literals or variables) as their operands and returns a single numerical value.
Example:
console.log(2+2);
console.log(10-4);
console.log(20/5);
console.log(5*5);
console.log("Remainder Operator " + 27%4);
output:
PS C:UsersThe-BeastDesktopjavascript Blog> node index.js
4
6
4
25
Remainder Operator 3
PS C:UsersThe-BeastDesktopjavascript Blog>
Increment and Decrement operator
var num = 15;
var newNum = num++;
console.log(num);
console.log(newNum);
output:
PS C:UsersThe-BeastDesktopjavascript Blog> node index.js
16
15
PS C:UsersThe-BeastDesktopjavascript Blog>
Postfix increment operator means the expression is evaluated first using the original value of the variable and then the variable is incremented(increased).
If used prefix, with the operator before operand (for example, ++x),
the increment operator increments and returns the value after incrementing.
Example:
var num = 15;
var newNum = ++num;
console.log(num);
console.log(newNum);
output:
PS C:UsersThe-BeastDesktopjavascript Blog> node index.js
16
16
PS C:UsersThe-BeastDesktopjavascript Blog>
Prefix increment operator means the variable is incremented first and then the expression is evaluated using the new value of the variable.
The decrement operator works the same as the increment operator.
3.Comparison operators
var a = 30;
var b = 10;
// Equal (==)
console.log(a == b);
// Not equal (!=)
console.log(a != b);
// Greater than (>)
console.log(a > b);
// Greater than or equal (>=)
console.log(a >= b);
// Less than (<)
console.log(a < b);
// Less than or equal (<=)
console.log(a <= b);
output:
PS C:UsersThe-BeastDesktopjavascript Blog> node index.js
false
true
true
true
false
false
PS C:UsersThe-BeastDesktopjavascript Blog>
4.Logical operators
Logical AND (&&)
The logical AND (&&) operator (logical conjunction) for a set of operands is true if and only if all of its operands are true.
Example:
var a = 30;
var b = -20;
console.log(a > b && b > -50 && b < 0);
output:
PS C:UsersThe-BeastDesktopjavascript Blog> node index.js
true
PS C:UsersThe-BeastDesktopjavascript Blog>
Logical OR (||)
var a = 30;
var b = -20;
console.log((a < b) || (b > 0) || (b > 0)); //false
Logical NOT (!)
The logical NOT (!) operator (logical complement, negation)
Example:
var a = 30;
var b = -20;
console.log(!((a>0) || (b < 0))); //false
5.String Concatenation(operators)
Example:
console.log("hello " + "world");
var myName = "Ro";
console.log(myName + " coderes");
output:
PS C:UsersThe-BeastDesktopjavascript Blog> node index.js
hello world
Ro coderes
PS C:UsersThe-BeastDesktopjavascript Blog>
6.Conditional (ternary) operator
The conditional (ternary) operator is the only JavaScript operator that takes three operands.
Example1:
var age=18;
age=age>=18 ? "you can vote" : "you can't vote"
console.log(age)
output:
PS C:UsersThe-BeastDesktopjavascript Blog> node index.js
you can vote
PS C:UsersThe-BeastDesktopjavascript Blog>
Example2:
var age=16;
age=age>=18 ? "you can vote" : "you can't vote"
console.log(age)
output:
PS C:UsersThe-BeastDesktopjavascript Blog> node index.js
you can't vote
PS C:UsersThe-BeastDesktopjavascript Blog>
Questions
1.What will be the output of 3**3?
console.log(3**3); // 3*3*3
output:
PS C:UsersThe-BeastDesktopjavascript Blog> node index.js
27
PS C:UsersThe-BeastDesktopjavascript Blog>
2.What is the Difference between == vs === ?
“==” He only checks the value, not the data types.
“===” He checks both data types and values. If both values and data types are the same, then the return will be true.
Example:
var num1 = 5; //number
var num2 = '5'; //string
console.log(typeof(num1));
console.log(typeof(num2));
console.log(num1 == num2 );
output:
PS C:UsersThe-BeastDesktopjavascript Blog> node index.js
number
string
true
PS C:UsersThe-BeastDesktopjavascript Blog>
Example:
var num1 = 5;
var num2 = '5';
console.log(typeof(num1));
console.log(typeof(num2));
console.log(num1 === num2 );
output:
PS C:UsersThe-BeastDesktopjavascript Blog> node index.js
number
string
false
PS C:UsersThe-BeastDesktopjavascript Blog>
Example:
var num1 = 5;
var num2 = 5;
console.log(typeof(num1));
console.log(typeof(num2));
console.log(num1 === num2
output:
PS C:UsersThe-BeastDesktopjavascript Blog> node index.js
number
number
true
PS C:UsersThe-BeastDesktopjavascript Blog>
watch the video:https://youtu.be/KGkiIBTq0y0
Wow, that’s what I was exploring for, what a data! existing here at this
web site, thanks admin of this site.
What’s up to every body, it’s my first pay a
quick visit of this web site; this website includes
remarkable and in fact fine information in favor of visitors.
Greetings from Idaho! I’m bored at work so I decided
to browse your site on my iphone during lunch break. I enjoy the info
you present here and can’t wait to take a
look when I get home. I’m shocked at how fast your blog loaded on my mobile
.. I’m not even using WIFI, just 3G .. Anyhow, wonderful
site!