Jump to content

Recommended Posts

Posted

 

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

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...