Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async & Performance Chapter 3: Promises - ReferenceError instead of TypeError #1266

Open
iDanbo opened this issue Mar 28, 2018 · 1 comment

Comments

@iDanbo
Copy link

iDanbo commented Mar 28, 2018

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?

@getify
Copy link
Owner

getify commented May 16, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants