Skip to content

Instantly share code, notes, and snippets.

@novonimo
Created September 13, 2019 07:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save novonimo/58a3b01f1a5d25e89de1f59074ee5d3f to your computer and use it in GitHub Desktop.
Save novonimo/58a3b01f1a5d25e89de1f59074ee5d3f to your computer and use it in GitHub Desktop.
/*
increase function will use number but it copy new number for use it
number is a Primitive type so ther are independent and will not change
*/
let number = 10;
function increase (param) {
param++;
console.log("param value is: ", param);
};
increase(number);
console.log("number value (Primitive type): ", number);
/*
but here object (reference type) will behave differnetly
*/
let object = {value: 10};
function increaseObject (param) {
param.value++
console.log("param value is: ", param);
}
increaseObject(object);
console.log("object value (Reference type): ", object)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment