Increment And Decrement Operators In Java Script | Complete Java Script Tutorials| #9

Published: 25 June 2023
on channel: Utkarsh Gupta
47
2

In this video we have discuss about one of the core and important concepts which is used in in the Java Script.

(INCREMENT OPERATOR )
The increment (++) operator increments (adds one to) its operand and returns the value before or after the increment, depending on where the operator is placed.
The ++ operator is overloaded for two types of operands: number and BigInt. It first coerces the operand to a numeric value and tests the type of it. It performs BigInt increment if the operand becomes a BigInt; otherwise, it performs number increment.

If used postfix, with operator after operand (for example, x++), the increment operator increments and returns the value before incrementing.

If used prefix, with operator before operand (for example, ++x), the increment operator increments and returns the value after incrementing.

The increment operator can only be applied on operands that are references (variables and object properties; i.e. valid assignment targets). ++x itself evaluates to a value, not a reference, so you cannot chain multiple increment operators together.
let x = 3;
const y = x++;
// x is 4; y is 3

let x2 = 3n;
const y2 = x2++;
// x2 is 4n; y2 is 3n

let x = 3;
const y = ++x;
// x is 4; y is 4

let x2 = 3n;
const y2 = ++x2;
// x2 is 4n; y2 is 4n

(Decrement Operator)
The decrement (--) operator decrements (subtracts one from) its operand and returns the value before or after the decrement, depending on where the operator is placed.
The -- operator is overloaded for two types of operands: number and BigInt. It first coerces the operand to a numeric value and tests the type of it. It performs BigInt decrement if the operand becomes a BigInt; otherwise, it performs number decrement.

If used postfix, with operator after operand (for example, x--), the decrement operator decrements and returns the value before decrementing.

If used prefix, with operator before operand (for example, --x), the decrement operator decrements and returns the value after decrementing.

The decrement operator can only be applied on operands that are references (variables and object properties; i.e. valid assignment targets). --x itself evaluates to a value, not a reference, so you cannot chain multiple decrement operators together.

Postfix decrement
JS
Copy to Clipboard

let x = 3;
const y = x--;
// x is 2; y is 3

let x2 = 3n;
const y2 = x2--;
// x2 is 2n; y2 is 3n
Prefix decrement
JS
Copy to Clipboard

let x = 3;
const y = --x;
// x is 2; y = 2

let x2 = 3n;
const y2 = --x2;
// x2 is 2n; y2 is 2n

We hope that you all like the video. Do share and subscribe the channel.

#javascript
#code #coding
#css
#html
#javascripttutorials
#codelover
#codelife
#codeschool
#increment
#decrement
#webdeveloper
#webdevelopment
#web


On this page of the site you can watch the video online Increment And Decrement Operators In Java Script | Complete Java Script Tutorials| #9 with a duration of hours minute second in good quality, which was uploaded by the user Utkarsh Gupta 25 June 2023, share the link with friends and acquaintances, this video has already been watched 47 times on youtube and it was liked by 2 viewers. Enjoy your viewing!