- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
JavaScript Object Methods
JavaScript Object Methods are the actions that can be performed on objects.
Following is the code showing methods present in object in JavaScript −
Example
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <style> body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .sample { font-size: 18px; font-weight: 500; color: red; } </style> </head> <body> <h1>JavaScript Object Methods</h1> Enter your Name <input type="text" class="name" /> Enter your Age <input class="age" type="number" /> <div class="sample"></div> <button class="Btn">CLICK HERE</button> <h3> Click on the above button to see if you are a legal adult or not </h3> <script> let sampleEle = document.querySelector(".sample"); let nameEle = document.querySelector(".name"); let AgeEle = document.querySelector(".age"); document.querySelector(".Btn").addEventListener("click", () => { let testObj = {name: nameEle.value, age: AgeEle.value,checkAdult() { if (this.age >= 18) { sampleEle.innerHTML = this.name + " you are a legal adult "; } else sampleEle.innerHTML = this.name + "you are not a legal adult "; }, }; testObj.checkAdult(); }); </script> </body> </html>
Output
On entering the name and age and clicking on ‘CLICK HERE’ button −
- Related Articles
- Get all methods of any object JavaScript
- How to add, access JavaScript object methods?
- Do you think JavaScript Functions are Object Methods?
- How to define methods for an Object in JavaScript?
- What are the methods of a boolean object in JavaScript?
- What are the methods of an array object in JavaScript?
- How to add properties and methods to an object in JavaScript?
- How to add properties and methods to an existing object in JavaScript?
- Is there a way to print all methods of an object in JavaScript?
- Share methods in JavaScript
- JavaScript - Get Date Methods
- JavaScript Set Date Methods
- JavaScript Basic Array Methods
- Static methods in JavaScript classes?
- Adding methods to Javascript Prototypes

Advertisements