0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【JavaScript】前置演算 と 後置演算【備忘録】

Posted at

インクリメント演算子とデクリメント演算子の前置と後置の違いのメモ。
どちらの場合もオペランドの値を1加算/減算するが、代入時の挙動が微妙に異なる。
※単純に代入処理が先か加算/減算が先かの違い

前置演算

インクリメント/デクリメントを行なってから代入処理を行う。

var x = 3;
var y = ++x;

console.log(x); // 4
console.log(y); // 4

後置演算

代入処理を行なってからインクリメント/デクリメントを行う。

var x = 3;
var y = x++;

console.log(x); // 4
console.log(y); // 3
0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?