JavaScript in Plain English

New JavaScript and Web Development content every day. Follow to join our 3.5M+ monthly readers.

Follow publication

Member-only story

Event Loop in JavaScript: How JavaScript Works Under the Hood

JavaScript is a single-threaded language. In other words, it can do only one thing at a time. JavaScript executes all operations on a single thread, but using a few smart data structures, gives us the illusion of multi-threading. The event loop is the secret behind JavaScript’s asynchronous programming.

JavaScript engine executes a script from the top and works its way down creating execution contexts and pushing and popping functions onto and off the call stack.

link

Behind the Scenes — How does the magic happen..!!

Javascript has a few interesting data structures that help it in appearing like a multi-threaded language.

1 — Call Stack

As the execution proceeds line by line, the method calls are pushed onto the call stack in order of execution. Once the execution is complete, the method is popped from the stack.

link

2 — Memory Heap

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Published in JavaScript in Plain English

New JavaScript and Web Development content every day. Follow to join our 3.5M+ monthly readers.

Written by Sumeet Bhalla

Javascript Professional experienced in creating Mobile/Web Apps using React/React Native. New to KOTLIN. Passionate about photography and solving problems.

No responses yet

Write a response