 Tutorial: Javascript Operator Web Developer

JavaScript Operator What is an Operator?

Let's look at a simple example. The expression 3 + 8 will give you 11. The operands in this case are 3 and 8, and the operator is '+'. JavaScript supports all this operators.

Assignment operator: The assignment operator (=) is used to give a variable a value.

Adding operator: You can use the plus sign (+) in adding two numbers together.

The Multiplying operator: The multiplication operator (*) is used to multiply two or more numbers.

A table of some operators can be found below.

JavaScript Arithmetic Operators

To perform arithmetic on numbers, arithmetic operators are used:

OperatorDescription
------
-Subtraction
------
*Multiplication
------
**Exponentiation (ES6)
------
/Division
------
%Modulus (Division Remainder)
------
++Increment
------
--Decrement

JavaScript Assignment Operators

JavaScript variables are assigned values using assignment operators.

OperatorExampleSame As
=x = yx = x + y
---------
+=x += yx = x + y
---------
-=x -= yx = x - y
---------
*=x *= yx = x * y
---------
/=x /= yx = x / y
---------
%=x %= yx = x % y

The assignment operator (+=) is used to add a value to a variable.

JavaScript code

 1 var x = 10; 2 x += 5; // Result 15

JavaScript String Operators

You can also use the + operator to join (concatenate) strings.

JavaScript code:

 1 var txt1 = 'Johnny'; 2 var txt2 = 'Smith'; 3 var txt3 = txt1 + ' ' + txt2;

The + operator is known as the concatenation operator when applied to strings.

When you put two numbers together, you'll get the sum, but when you combine a number and a string, you'll get a string:

JavaScript code

 1 var x = 5 + 5; // Result 10 2 var y = '5' + 5; // Result 55 3 var z = 'Hello' + 5; // Result Hello5

Adding a number to a string will simply give you a string.

JavaScript Comparison Operators

OperatorDescription
==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
------
?operator job

JavaScript Logical Operators

OperatorDescription
&&logical and
------
IIlogical or
------
!logical not

JavaScript Type Operators

OperatorDescription
typeofReturns the type of a variable
------
instanceofReturns true if an object is an instance of an object type. Create Stunning websites and web apps

Trying to build out all user interfaces and components for your website or web app from scratch can become a very tedious task. A huge reason why we created Contrast Bootstrap to help reduce the amount of time we spend doing that, so we can focus on building some other aspects of the project. Contrast Bootstrap PRO consists of a UI Kit featuring over 10000+ component variants. Together with a template of 5 admin dashboards and 23+ additional multipurpose pages template for building almost any type of website or web app. You can view a demo and learn more about Contrast by clicking here.Try contrast pro Contrast Bootstrap PRO was built using the most popular CSS framework Bootstrap to help build your next landing, admin SAAS, prelaunch etc project with a clean, prebuilt and well documented template and UI components.Learn more about Contrast

Related Posts