Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q1590 Does JavaScript do 'call by reference' or 'call by value'?

You are here: irt.org | FAQ | JavaScript | Object | Q1590 [ previous next ]

Variables are 'call by value', whereas objects are 'call be reference' as the following shows:

<script language="JavaScript"><!--
function byValue(a_variable) {
  a_variable *= a_variable;
}

function byReference(an_object) {
  an_object.a_property *= an_object.a_property;
}

var x = 12;
byValue(x);
document.write(x + '<br>'); // displays 12

var y = new Object();
y.a_property = 12;
byReference(y);
document.write(y.a_property + '<br>'); // displays 144
//--></script>

Feedback on 'Q1590 Does JavaScript do 'call by reference' or 'call by value'?'

©2018 Martin Webb