A
method is a function that is property of an object.
In the above example, toString() is a method, whereas square is a function.
HelloWorld.js
var employee = { name : "krishna", age : 29, toString: function(){ return "name : " + this.name + ", age : " + this.age + "]"; } } function square(num){ return num * num; } console.log(employee); console.log(`Square of 10 is ${square(10)}`);
In the above example, toString() is a method, whereas square is a function.
No comments:
Post a Comment