Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to return an object from a JavaScript function?
To return an object from a JavaScript function, use the return statement, with this keyword.
Example
You can try to run the following code to return an object from a JavaScipt function −
<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