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

Veröffentlicht am: 25 Juni 2023
auf dem Kanal: 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


Auf dieser Seite können Sie das Online-Video Increment And Decrement Operators In Java Script | Complete Java Script Tutorials| #9 mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Utkarsh Gupta 25 Juni 2023 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 47 Mal angesehen und es wurde von 2 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!