Jump to content
Killersites Forums

What is the difference between “return” and “return value” in JavaScript?


SubhanUllah
 Share

Recommended Posts

 

Both do exactly the same if and only if value===undefined. The following example demonstrates the differences.

function f1() { 
} // no return statement returns undefined. 
 
function f2() { 
        return; 
} // returns undefined too.  The undefined is implicit here. 
 
function f3() { 
        return undefined; 
} // explicitly returns undefined 
 
function f4() { 
        return 1; 
} // returns 1.   
 
console.log('f1() === ' + f1()); // prints: f1() === undefined 
console.log('f2() === ' + f2()); // prints: f2() === undefined 
console.log('f3() === ' + f3()); // prints: f3() === undefined 
console.log('f4() === ' + f4()); // prints: f4() === 1

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...