An open API service indexing awesome lists of open source software.

https://github.com/ai-balushi/prefix-postfix

This project illustrates the difference between prefix and postfix operators in TypeScript. Prefix operators increment the value before it is used, while postfix operators increment the value after it is used. The code examples demonstrate these concepts with simple arithmetic operations.
https://github.com/ai-balushi/prefix-postfix

postfix prefix

Last synced: 6 days ago
JSON representation

This project illustrates the difference between prefix and postfix operators in TypeScript. Prefix operators increment the value before it is used, while postfix operators increment the value after it is used. The code examples demonstrate these concepts with simple arithmetic operations.

Awesome Lists containing this project

README

          

Prefix & Postfix Increment Examples
This code snippet demonstrates the difference between prefix and postfix increment operators in JavaScript.

Prefix Example
let a = 10;
++a;
console.log(a); // Output: 11
In the prefix example, ++a increments the value of a before it's used in the expression. So, the value of a becomes 11.

Postfix Example
let b = 10;
b++;
console.log(b); // Output: 11
In the postfix example, b++ uses the current value of b in the expression, then increments b. So, the value of b becomes 11.

More Examples
let x = 5;
let y = ++x;
console.log(x); // Output: 6
console.log(y); // Output: 6
In the prefix increment, ++x increments x first (to 6), then assigns the new value of x to y.

let m = 5;
let n = m++;
console.log(m); // Output: 6
console.log(n); // Output: 5
In the postfix increment, m++ assigns the current value of m to n (5), then increments m.

This README provides a brief explanation of prefix and postfix increment examples along with their outputs.