May 29, 20224 min

JavaScript Class Notes: Operators

Updated: Oct 16, 2022

Mobiprep has created last-minute notes for all topics of Javascript to help you with the revision of concepts for your university examinations. So let’s get started with the lecture notes on javascript.

  1. JavaScript: Introduction

  2. Data Types

  3. Variables

  4. Operators

  5. Functions

  6. Conditional Statements and Loops

  7. Arrays

  8. Objects

  9. DOM Elements

  10. Cookies

  11. Pop Up Box

  12. Exception Handling

Our team has curated a list of the most important questions asked in universities such as DU, DTU, VIT, SRM, IP, Pune University, Manipal University, and many more. The questions are created from the previous year's question papers of colleges and universities.

  1. Explain arithmetic and assignment operators in JavaScript.

  2. What is the difference between == and ===?

  3. Explain comparison and logical operators in JavaScript.

  4. Write a note on Bitwise Operators in JavaScript.

  5. Write a note on string operators used in JavaScript.

  6. Write a note on Boolean operators in JavaScript.

  7. Explain the use of Infinity and NaN function in JavaScript.

  8. Explain the use of 'typeof' operator.

JavaScript Notes: Operators

Question 1. Explain arithmetic and assignment operators in JavaScript.

Assignment operator assigns a value to left operand from right operand. The equal (=), assigns the value of its right operand to its left operand. In example x = y assigns the value of y will be assigned to x.

There are compound assignment operators which are explained below.

Arithmetic operators:

An arithmetic operator accepts numerical values as their operands and returns a single numerical value. The arithmetic operators are addition (+), subtraction (-), multiplication (*), and division (/). In addition to the standard arithmetic operations (+, -, *, /), JavaScript provides the arithmetic operators listed below.


Question 2. What is the difference between == and ===?


Question 3. Explain comparison and logical operators in JavaScript.

1) Comparison operators — operators that compare values and return true or false. The operators include:

  • Less than (<) — returns true if the value on the left is less than the value on the right, otherwise it returns false.

  • Greater than (>) — returns true if the value on the left is greater than the value on the right, otherwise it returns false.

  • Less than or equal to (<=) — returns true if the value on the left is less than or equal to the value on the right, otherwise it returns false.

  • Greater than or equal to (>=) — returns true if the value on the left is greater than or equal to the value on the right, otherwise it returns false.

  • Equal to (===) — returns true if the value on the left is equal to the value on the right, otherwise it returns false.

  • Not equal to (!==) — returns true if the value on the left is not equal to the value on the right, otherwise it returns false.

2) Logical(Boolean) operators — operators that combine multiple boolean expressions or values and provide a single boolean output. The operators include:

  • && (and) — This operator will be truth (act like true) if and only if the expressions on both sides of it are true.

  • || (or) — This operator will be truth if the expression on either side of it is true. Otherwise, it will be false (act like false).

  • ! (not) _this returns opposite of the input.


Question 4. Write a note on Bitwise Operators in JavaScript.

  • Bitwise operators treat its operands as a group of 32-bit binary digits and perform actions. But, the result is shown as a decimal value.

  • Bitwise AND:

  • Bitwise AND & returns 1 if both operands are 1 else it returns 0.

  • Bitwise OR:

  • Bitwise OR | returns 1 if either of the corresponding bits of one operand is 1 else returns 0.

  • Bitwise XOR:

  • Bitwise XOR ^ returns 1 if the corresponding bits are different and returns 0 if the corresponding bits are the same.

  • Bitwise NOT:

  • Bitwise NOT ~ inverts the bit( 0 becomes 1, 1 becomes 0).

  • Bitwise SHIFT operators:

  1. LEFT SHIFT <<: I.e. shifts the elements to the left and insert 0 in the gap formed. For example, 15<<1 or 1111<<1 implies 1110 or 14.

  2. RIGHT SHIFT >>>: It is just the reverse of LEFT SHIFT, that is 15>>>1 or 1111>>>1 implies 0111 or 7.

  3. SIGNED RIGHT SHIFT >>: i.e. it returns the signed right shift. For example, 1111>>1 or 0111 or 7. Since the fourth bit is 0, positive.


Question 5. Write a note on string operators used in JavaScript.

The + operator, += operator used to concatenate strings.

Given that text1 = "Good ", text2 = "day", and text3 = text1 + text2 then text3=goodday.


Question 6. Explain the use of 'let' keyword in JavaScript.

Nan function :

Definition and Usage

The isNaN() function checks whether a value is a valid number

This function returns true if the value equal to Nan result . Otherwise it returns false.

This function is different from the.isNaN() method.

The global isNaN() function, converts the tested value to a Number, once conversion is done then tests it.

Example:

isNaN(123) //false

isNaN(-1.23) //false

isNaN(5-2) //false

isNaN(0) //false

isNaN('123') //false

isNaN('Hello') //true

isNaN('2005/12/12') //true

isNaN('') //false

isNaN(true) //false

isNaN(undefined) //true

isNaN('NaN') //true

isNaN(NaN) //true

isNaN(0 / 0) //true

isNaN(null) //false

Infinity function :

Division by 0 gives you another special value:

> 3/0

Infinity

You can’t perform any operation on positive and negative infinity against each other:

> Infinity - Infinity

NaN

It is still infinity:

> Infinity + Infinity

Infinity

> 5 * Infinity

Infinity

Question 7. Is there any ternary operator in JavaScript?

Yes, ‘?’ is the ternary operator. It is same as in C. That is, (condition? true: false).

For example, (12>2?1:0) returns 1.


Question 8. Explain the use of 'typeof' operator.

The uses of typeof operator are listed below:

  • Type of can be used to check whether a variable exists and it has a value.

  • The typeof operator used for checking that a value is neither undefined nor null.

  • It differentiate between objects and primitives.

  • It tells What is the type of a primitive value.

  • typeof check whether a value is a function.



Mobiprep is a one stop solution for all exam preparation needs. Get all exam prep resources at a single platform.

Back to Top


    4280
    2