[[JavaScript]]や[[TypeScript]]は[[参照の値渡し]]。[[仮引数]]への再代入や直接操作は影響ないが、[[仮引数]]のプロパティに対して操作が行われると、[[実引数]]のそれにも影響が出る。
```ts
interface Coordinate {
x: number
y: number
}
function destroyArgString(x: string) {
x = "wriiiiiiiiiiiiiiiiiii"
}
function destroyArgObject(s: Coordinate) {
s = {
x: 65535,
y: 65535,
}
}
function destroyArgObjectReference(s: Coordinate) {
s.x = 65535
s.y = 65535
}
function main() {
let x = "init"
destroyArgString(x)
console.log(x)
// "init"
let s1 = { x: 0, y: 0 }
destroyArgObject(s1)
console.log(s1)
// { "x": 0, "y": 0 }
let s2 = { x: 0, y: 0 }
destroyArgObjectReference(s2)
console.log(s2)
// { "x": 65535, "y": 65535 }
}
main()
```
<button class="playground"><a href="https://www.typescriptlang.org/play?#code/JYOwLgpgTgZghgYwgAgMIHt1QCajpZAbwChkzkAPALmRAFcBbAI2lPIE8b7nWBfY4jDogEYYOhDJsEAM5go6dgEEoAcwDK80KoAU1ZHKjaAlETZkKyALzIARAHcjwZy9duXt4v0HDR4ydKGiiqqAPJMAFYQojoyNBhYuCD4EKYk5AbWZhkZ+gBsAKwFAMwFADTmOZzIhSXllfzeQiJiElKy8sFq4VGiAEoQMNAQIhCx8Zg4eJBplTIAdJY2taVz8+xZKwVeAs1+bQxwoDqzGQA2EGCUWbagwGCeGYGdymqaRiC6FMaVCBIy6Au8zO6C+PwyAHoIXY7g8BOdLgYAIxZQiUGgABjKyGqGOQ-CeHQUrzCkWiYFiSPB5D+IABQJBuhkVMqUKIdgotkx2Ns7C5yDx3gRVxkACZUeiBdjcfjKs9iSEeuSBkMoCMkLFRdSyLT6RBgaDNdrkGy0bZOTQtjy+ZaiqVZd5DsdjEA">Playground</a></button>
## 参考
- [ECMA\-262\-3 in detail\. Chapter 8\. Evaluation strategy – Dmitry Soshnikov](http://dmitrysoshnikov.com/ecmascript/chapter-8-evaluation-strategy/)