
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
- Related Questions & Answers
- How to return an object from a function in Python?
- How to remove a function from an object in JavaScript?
- How to return a json object from a Python function?
- How to return a matplotlib.figure.Figure object from Pandas plot function?
- How to return a value from a JavaScript function?
- How to return a string from a JavaScript function?
- How to return value from an asynchronous callback function in JavaScript?
- How to return a JSON object from a Python function in Tkinter?
- How to return an array from a function in C++?
- How to pass an object as a parameter in JavaScript function?
- How to return object from an array with highest key values along with name - JavaScript?
- How can we use a JavaScript function as an object?
- How to call a JavaScript function from an onClick event?
- How to call a JavaScript function from an onsubmit event?
- How to call a JavaScript function from an onmouseover event?
Advertisements