- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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
What is the difference between functions and methods in JavaScript?
Functions and methods are the same in JavaScript, but a method is a function, which is a property of an object.
The following is an example of a function in JavaScript −
function functionname(param1, param2){ // code }
Example
The method is a function associated with an object. The following is an example of a method in JavaScript −
<html> <head> <script> var employee = { empname: "David", department : "Finance", id : 002, details : function() { return this.empname + " with Department " + this.department; } }; document.write(employee.details()); </script> </head> </html>
Output
Advertisements