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

Publicado em: 25 Junho 2023
no canal de: 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


Nesta página do site você pode assistir ao vídeo on-line Increment And Decrement Operators In Java Script | Complete Java Script Tutorials| #9 duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário Utkarsh Gupta 25 Junho 2023, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 47 vezes e gostou 2 espectadores. Boa visualização!