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 trial

JavaScript Using SQL ORMs with Node.js Getting Started with Sequelize Install and Configure Sequelize and SQLite

Amanda Richardson
seal-mask
.a{fill-rule:evenodd;}techdegree
Amanda Richardson
Web Development Techdegree Student 13,776 Points

syntax of async function here

I am confused on the syntax here - specifically that the function starts with a parentheses and I haven't seen that used - instead seeing async function (). I can't find reference to this in MDN. What is the meaning of the first parentheses here and why are we nesting this function in parentheses? Or am I just completely misunderstanding this code? ... (async () => { // Sync 'Movies' table await sequelize.sync({ force: true });

try { const movie = await Movie.create({ title: "Toy Story", }); console.log(movie.toJSON()); } catch (error) { console.error("Error connecting to the database: ", error); } })(); ...

1 Answer

Surrounding the function with parentheses makes it an IIFE (Immediately Invoked Function Expression). Here is the link to the MDN article on it.