Skip to main content

Command Palette

Search for a command to run...

JavaScript 10

The Real-Deal with Examples

Published
3 min readView as Markdown
JavaScript 10
A

I am a passionate front-end engineer with 3 years of experience in developing and implementing innovative software solutions.

Javascript Operators

JS operator are used to perform particular actions. They can be used to assign values, combine values, perform arithmetic operations and more. JS operators are symbols (or set of symbols) or keywords.

There are different types of operators namely:

  • Assignment Op
  • Arithmetic Op
  • Comparison Op
  • Logical Op

    1.Assignment Opertors

    The assignment operator is used to assign a value to a variable. It uses the equal = symbol.
var x = 3; // assigns number 3 to x
var y = 7; // assigns number 7 to y
var sum = x + y; // assigns the sum of x and y to sum
document.write(sum); // prints sum

2. Arithmetic Operators

The arithmetic operators are used to perform arithmetic operations (like addition, subtraction, multiplication, and division) between values. Here are the symbols used for the arithmetic operators:

  • Addition: +
  • Subtraction: -
  • Multiplication: *
  • Division: /

Addition Example:

var num1 = 3; // assigns number 3 to num1
var num2 = 7; // assigns number 7 to num2
var sum = num1 + num2; // assigns the sum of num1 and num2 to sum
document.write(sum); // prints sum

Subtraction Example:

var num1 = 3; // assigns number 3 to num1
var num2 = 7; // assigns number 7 to num2
var difference = num1 - num2; // assigns the difference of num1 and num2 to difference
document.write(difference); // prints difference

Multiplication Example:

var num1 = 3; // assigns number 3 to num1
var num2 = 7; // assigns number 7 to num2
var product = num1 * num2; // assigns the product of num1 and num2 to product
document.write(product); // prints the product

Division Example:

var num1 = 3; // assigns number 3 to num1
var num2 = 7; // assigns number 7 to num2
var quotient = num1 / num2; // assigns the quotient of num1 and num2 to quotient
document.write(quotient); // prints the quotient

3. Comparison Operators

Comparison operators compare its operands and return a Boolean based on whether the comparison is true or false. In the example below, the equality comparison operator is used to compare two numbers.

var x = 5;
var y = 5;
document.write(x == y); // prints true because x and y are equal

4. Logical Operators

Logical operators are typically used with Boolean values. They are used to determine the logic between its operands.

true && true;  // returns true
true && false; // returns false  
true || true;    // returns true
2 == 2 || 2 == 3; // returns true

Thanks for reading!!

JavaScript

Part 10 of 11

This blog is all about JavaScript topics from Basics to Advance, along with interview question.

Up next

JavaScript 11

With Examples

More from this blog

A

Arizon.Dev

12 posts

Hi everyone, My name is Arinze Calistus and I'm a self-taught Full-Stack developer that learned and is still learning through online resources. I would love to connect with people and have a chat.