search
HomeCommon ProblemWhat is the difference between x-- and --x

The difference between x-- and --x: 1. [--x] decrements the value of x by 1 first, and then calculates the value of x; 2. [x--] calculates x first value, and then decrement the value of x by 1.

What is the difference between x-- and --x

##The difference between x-- and --x:

  • - -x means that the value of x is decremented by 1 first, and then the value of x is calculated.

  • x-- is to first calculate the value of x, and then decrement the value of x by 1.

Example 1:

var x = 10;
console.log(x--);
console.log(x);

Output:

10
9

The first output is 10, x--first use the value of x in the current expression , and then decrement the value of x by 1; the second output is 9, because x has decremented by 1 after the previous instruction.

Example 2:

var x = 10;
console.log(--x);
console.log(x);

Output:

9
9

The first output is 9, --x first decrements the value of x by 1, and then in the current expression Use the value of x; the second one also outputs 9, and x has been decremented by 1 after the previous instruction.

The above is the detailed content of What is the difference between x-- and --x. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment