Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Adding a Method to a JavaScript Object

// creating an object
let student = { };

// adding a property
student.name = 'John';

// adding a method
student.greet = function() {
    console.log('hello');
}

// accessing a method
student.greet(); // hello
 
PREVIOUS NEXT
Tagged: #Adding #Method #JavaScript #Object
ADD COMMENT
Topic
Name
6+8 =