You-dont-know-js: Async & Performance Chapter 3: Promises - ReferenceError instead of TypeError

Created on 28 Mar 2018  路  1Comment  路  Source: getify/You-Dont-Know-JS

https://github.com/iDanbo/You-Dont-Know-JS/blob/master/async%20%26%20performance/ch3.md#swallowing-any-errorsexceptions

var p = new Promise( function(resolve,reject){
    resolve( 42 );
} );

p.then(
    function fulfilled(msg){
        foo.bar();
        console.log( msg ); // never gets here :(
    },
    function rejected(err){
        // never gets here either :(
    }
);

I get a ReferenceError: foo is not defined instead of TypeError. Is it a typo?
As I understood, the error will be caught anyway because of the spec changes, so running the code in Chrome will give Uncaught (in promise) ReferenceError: foo is not defined. But where is the TypeError?

for second edition

Most helpful comment

You're correct, should have been ReferenceError. I think this was a missed detail when the code snippet was refactored from an earlier version. Will address in second edition.

>All comments

You're correct, should have been ReferenceError. I think this was a missed detail when the code snippet was refactored from an earlier version. Will address in second edition.

Was this page helpful?
0 / 5 - 0 ratings