Call by Value and Call by Reference in Javascript
Call By Value
ex:
function ByValue( o)
{
o*=o;
}
var x=4;
ByValue(x);
alert(x);// result will be 4
Call By Reference
ex:
var obj= new Object();
obj.newProperty=4;
ByRef(obj);
function ByRef(obj)
{
obj.newProperty*=obj.newProperty;
}
alert(obj.newProperty);// result will be 16
Happy Living...
Happy Coding...
Happy Concepts...
Call By Value
ex:
function ByValue( o)
{
o*=o;
}
var x=4;
ByValue(x);
alert(x);// result will be 4
Call By Reference
ex:
var obj= new Object();
obj.newProperty=4;
ByRef(obj);
function ByRef(obj)
{
obj.newProperty*=obj.newProperty;
}
alert(obj.newProperty);// result will be 16
Happy Living...
Happy Coding...
Happy Concepts...
No comments:
Post a Comment