object as function javascript code example
Example 1: object methods in javascript
const testScore = {
damon: 89,
shawn: 91,
keenan: 80,
kim: 89,
};
Object.keys(testScore);
Object.values(testScore);
Object.entries(testScore);
for (let person in testScore) {...}
for(let score of Object.values(testScore)){
console.log(score)
}
Example 2: adding function to objects js
var myObj = {
myFunc: function(param){
}
}
Example 3: Object as a Function
const profileUpdate = ({ name, age, nationality, location }) => {
}
Example:
const stats = {
max: 56.78,
standard_deviation: 4.34,
median: 34.54,
mode: 23.87,
min: -0.75,
average: 35.85
};
const half = ({ max, min }) => (max + min) / 2.0;
console.log(half(stats));