4 ms·
ok, so what does this print? try { return console.log('one'); } catch(err) { return console.log('two'); } finally { return consol
by jonny_eh 5y ago
ok, so what does this print?
try {
return console.log('one');
} catch(err) {
return console.log('two');
} finally {
return console.log('three');
}
Tip: The results are "odd".
- re 5y agoNot sure I'm call them odd -- it prints the same thing that would be printed without the "returns" (i.e., if the blocks contained only console.log calls), which is what I'd expect it to print: 'one' followed by 'three'. You're maybe thrown off because, while only one return statement can successfully return a value from the function, more than one can be executed, with their values evaluated.
- jonny_eh 5y ago> 'one' followed by 'three' Right! Those are the "odd" numbers! ;)
- valbaca 5y agoUncaught SyntaxError: Illegal return statement You're trying to return the result of console.log, which is undefined, which you cannot return explicitly
- Twixes 5y agoYou very much can return `undefined`, it's just that `return` only works inside of a function, not if you just copy the block of code into the console :)
- edflsafoiewq 5y agoWhat's "odd" about it? It does exactly what I'd expect.
- HJain13 5y agoOne and three are "odd" numbers