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.
- Host: GitHub
- URL: https://github.com/ai-balushi/prefix-postfix
- Owner: AI-Balushi
- Created: 2024-03-18T10:22:16.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-19T05:34:14.000Z (over 2 years ago)
- Last Synced: 2025-11-01T07:02:58.774Z (8 months ago)
- Topics: postfix, prefix
- Language: TypeScript
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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.