5
2

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 1 year has passed since last update.

【問答無用】JavaScriptに引数の参照渡しは無い

Posted at

「参照渡し」 無い

function f(&n) { // こんな構文は『無い』ので実行できない
  n = 2;
}

var n = 1;
f(n);
console.log(n); // 参照渡しができたとしたら、出力:2になる

「値渡し」 有る

function f(n) {
  n = 2;
}

var n = 1;
f(n);
console.log(n); // 出力:1

「(オブジェクト)参照」 有る

var o1 = { value: 1 };
var o2 = o1;

o2.value = 2;

console.log(o1.value); // 出力:2

『「参照」の「値渡し」』 有る

function f(n) {
  n.value = 2;
}

var n = { value: 1 };
f(n);
console.log(n.value); // 出力:2
5
2
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
5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?