Home >Web Front-end >JS Tutorial >The difference between value types and reference types

The difference between value types and reference types

巴扎黑
巴扎黑Original
2016-12-19 14:24:001109browse

<script type="text/javascript">
var i = 1;
var j = 2;
var a = [1, 2];
function arr(b) {
  b[0] = 2;
}
function me(x, y) {
 x = x+y;
return x;
}
arr(a);
console.log(i); // 1
console.log(JSON.stringify(a)); // [2,2]
</script>

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