Skip to main content

Node.js #3- Operators

Operators
An operator performs some operation on single or multiple operands (data value) and produces a result. For example 1 + 2, where + sign is an operator and 1 is left operand and 2 is right operand. + operator adds two numeric values and produces a result which is 3 in this case.

 
Syntax:
<Left operand> operator <right operand>
 
<Left operand> operator

Example 1: Arithmetic Operators
Arithmetic operators are used to perform mathematical operations between numeric operands.
Source code:
var x = 10, y = 10
console.log("Addition Operator",x + y)
console.log("Subtraction Operator",x - y)
console.log("Multiplication Operator",x * y)
console.log("Division Operator",x / y)
console.log("Modulus Operator",x % y)
console.log("Increment Operator",x++)
console.log("Decrement Operator",y--)
 
Output:
Addition Operator 20
Subtraction Operator 0
Multiplication Operator 100
Division Operator 1
Modulus Operator 0
Increment Operator 10
Decrement Operator 10

Example 2: Comparison Operators
Comparison operators are used to compare two operands and return Boolean value true or false.
Brief:
==           Compares the equality of two operands without considering type.
===        Compares equality of two operands with type.
!=            Compares inequality of two operands.
>             Checks whether left side value is greater than right side value. If yes then returns true otherwise false.
<             Checks whether left operand is less than right operand. If yes then returns true otherwise false.
>=           Checks whether left operand is greater than or equal to right operand. If yes then returns true otherwise false.
<=           Checks whether left operand is less than or equal to right operand. If yes then returns true otherwise false.


Source code:
var x = 10, y = 10
console.log("equality Operator of two operands without considering type ::",x == y)
console.log("equality Operator of two operands with type ::",x === y)
console.log("inequality Operator ::",x != y)
console.log("greaterthan Operator ::",x > y)
console.log("lesserthan Operator ::",x < y)
console.log("greaterthan equal Operator ::",x >= y)
console.log("lesserthan equal Operator ::",x <= y)

Output:
equality Operator of two operands without considering type :: true
equality Operator of two operands with type :: true
inequality Operator :: false
greaterthan Operator :: false
lesserthan Operator :: false
greaterthan equal Operator :: true
lesserthan equal Operator :: true

Example 3: Logical Operators
Logical operators are used to combine two or more conditions.
Brief:
&&         is known as AND operator. It checks whether two operands are non-zero (0, false, undefined, null or "" are considered as zero), if yes then returns 1 otherwise 0.
||           is known as OR operator. It checks whether any one of the two operands is non-zero (0, false, undefined, null or "" is considered as zero).
!              is known as NOT operator. It reverses the boolean result of the operand (or condition)
Source code:
var x = 10, y = 10
console.log("AND  Operator::",(x != y) && (x < y))
console.log("OR  Operator::",(x != y) || (x < y))
console.log("NOT  Operator::",(x!=y))
 
Output:
AND  Operator:: false
OR  Operator:: false
NOT  Operator:: false

Example 4: Assignment Operators
Assignment operators are used to assign values to variables with less key strokes.
Brief:
=             Assigns right operand value to left operand.
+=           Sums up left and right operand values and assign the result to the left operand.
-=            Subtract right operand value from left operand value and assign the result to the left operand.
*=           Multiply left and right operand values and assign the result to the left operand.
/=           Divide left operand value by right operand value and assign the result to the left operand.
%=          Get the modulus of left operand divide by right operand and assign resulted modulus to the left operand.
Source code:
var x = 10, y = 10
console.log("= Operator::",x = y)
console.log("+= Operator::",x += 1)
console.log("-= Operator::",x -= 1)
console.log("*= Operator::",x *= 5)
console.log("/= Operator::",x /= 5)
console.log("%= Operator::",x %= 2)
 
Output:
= Operator:: 10
+= Operator:: 11
-= Operator:: 10
*= Operator:: 50
/= Operator:: 10
%= Operator:: 0

Example 5: Conditional Operators (or) ternary operator
Special operator called ternary operator (or) Conditional Operators :? That assigns a value to a variable based on some condition. This is like short form of if-else condition.
Syntax:
<condition> ? <value1> : <value2>;

Brief:
Conditional operator starts with conditional expression followed by ? operator. Second part ( after ? and before : operator) will be executed if condition turns out to be true. If condition becomes false then third part (after :) will be executed.
Source code:
var a = 10, b = 5;
var c = a > b? a : b; 
var d = a > b? b : a; 
console.log(c,d)
 
Output:
10 5
 
Thank you, Come Back to Learn More About Tech Stuff with Tech Bird
Have A Nice Day ! 
:)

Comments

Popular posts from this blog

BIG DATA ANALYTICS

BIG DATA ANALYTICS Have you ever hit upon how Amazon and Flip kart could possible verdict what we want; how the Google auto completes our search; how the YouTube looks into videos we want to watch? When we open YouTube, we will be at sixes and sevens, when we find ads related to what we have searched earlier in the past days. This is where we find ourselves in the era of big data analytics. More than 3 trillion bytes of information are being generated everyday through our smart phones, tablets, GPS devices, etc.  Have we thought about what can be done with all these information? This is where the data analytics comes into play. Big data analytics is just the study of future build up to store data in order to extract the behaviour patterns. The entire social networking website gathers our data which are related to our interest which is usually done by using our past search or any other social information. Data analytics will lead to a walkover in near future. 

Amazon Elastic Compute Cloud (Amazon EC2)

Amazon Elastic Compute Cloud (Amazon EC2) What is AWS EC2 ? Amazon Elastic Compute Cloud, EC2 is a web service from Amazon that provides resizable compute services in the cloud. What do you mean by resizable in AWS EC2 ? You can quickly scale up or scale down the number of server instance you are using based upon on your traffic.  What is called as Instance? An instance is a virtual server for running applications on Amazon’s EC2. Simply Virtual Machine is called as Instance(i.e)it holds the HDD, OS, RAM, Network Connection Whatever things that are need to run a system.  Note : Everything is Virtual You can’t able to see the HDD, RAM , or CPU. Only thing is you can able to configure it based on your need.    So here is the Definition….  Amazon Elastic Compute Cloud (Amazon EC2) is a web service that provides secure, resizable compute capacity in the cloud. It is designed to make web-scale cloud computing easier for developers. Why Amazon EC2 ?   Pay-as-you

CLOUD COMPUTING SERVICES

Services provided by Cloud Computing   1. Software as a service :  It is process by which the software will be provided by the cloud server's. Instead of using the software in our local machine we can directly use the cloud services directly to get our work done.   Example : Google Slides, Google Docs, Google Sheets, Zoho Writer,....etc. 2. Platform as a service : It is process by which you can directly use platform like windows , linux , Mac, ....Which ever you need to done your work. Example : There are certain software which might be run only certain platform. Assume I have windows operating system but i am doing research in BIG DATA. There Linux Operation system might be handy for my research work. Where it is hard for me to put Operating System again and again to my local machine and taking backup data. So Cloud Computing Services Makes our work easier whatever platform we need it will provide us without any loss in data or hard backup pro