object reference javascript code example
Example 1: object object javascript
person = {
'name':'john smith'
'age':41
};
console.log(person);
//this will return [object Object]
//use
console.log(JSON.stringify(person));
//instead
Example 2: javascript pass by reference
function add(a, b, output) {
output.out = a + b;
}
var output = {};
add(5, 3, output);
console.log(output); //output: {out: 8}
Example 3: object literal javascript
// Object literals are defined using the following syntax rules:
// A colon separates property name from value.
// A comma separates each name-value pair from the next.
// There should be no comma after the last name-value pair.
// If any of the syntax rules are broken, such as a missing comma or colon or curly brace,
// an error will be thrown.
var myObject = {
sProp: 'some string value',
numProp: 2,
bProp: false
};
Example 4: js create object with properties
var mycar = new Car('Eagle', 'Talon TSi', 1993);
Example 5: js create object with properties
function Car(make, model, year) {
this.make = make;
this.model = model;
this.year = year;
}