Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJesse Dispoto
Front End Web Development Techdegree Graduate 14,538 PointsWhat is the "new" keyword? The function still works if you omit "new" and just put "throw", so what is the point of new?
What does "new" do in this instance? The console seems to throw an error either way, with or without new.
1 Answer
Steven Parker
231,236 PointsThe "throw
" will still generate the event.
The "new
" keyword constructs an object instance of the type specified to pass as the argument to the handler.
Also, depending on how they are coded, some objects can be created by calling them even without the "new
" operator. But not all can, so it's a good idea to always use it.