Introduction
Return Boolean Type
We can return any predefined data type like Boolean, string, array, and many more. Here the hello() function returns a Boolean value. Here is the sample code.
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- </head>
- <body>
- <script>
- function hello() {
- return true;
- }
- alert(hello());
- </script>
- </body>
- </html>

Return Object from Function
We can return an object from a JavaScript function. In this example we are returning a “person” object from the hello() function and then we are showing the return value. Here is a sample example.
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- </head>
- <body>
- <script>
- function hello() {
- var student = new Object();
- student.name = "Rama";
- student.surname = "Sagar";
- return student;
- }
- var p = hello();
- alert(p.name + " " + p.surname);
- </script>
- </body>
- </html>



Join the conversation! Your thoughts help the community grow.