DEV Community

Cover image for Essential Concepts in JS

Essential Concepts in JS

Ritik Ambadi on August 28, 2021

For first-timers , Javascript might seem easy at first with its C-like syntax... However the way it runs, the constant changes that are made to th...
Collapse
 
jcubic profile image
Jakub T. Jankiewicz • Edited

It's worth reading, NodeJS is JavaScript and it's not single threaded at all.

Node.js is not single threaded

The true is that browser have single tread not JavaScript. But this is also not true because you have web workers.
In any language when you create while(true) {} loop you will block the tread, unless you will spawn another tread, with Web Worker you can do the same what you can do with Java. while(true){} will not block the web worker.

Collapse
 
vladmel1234 profile image
vlad melnik

Hey, NodeJS is not JavaScript, it is environment to run javascript, and JS is single threaded because it runs in a single thread provided by this env.
And the not single threaded part of Nodejs is C++ part

Collapse
 
jcubic profile image
Jakub T. Jankiewicz

You're not correct, JavaScript is not single threaded, the environment is single threaded. The way the language is implemented. The same way JavaScript is not asynchronous that is provided by environment (browser or NodeJS). Environment is not part of the language.

Collapse
 
aritik profile image
Ritik Ambadi

You're right Vlad. The underlying C++ part is multi-threaded. The NodeJS part is single-threaded and I think the intention is for NodeJS developers to write code in a single-threaded manner.

For anybody , who wants to understand these concepts in detail , I used Stephen Grider's Advanced NodeJS course on Udemy.

udemy.com/course/advanced-node-for...

Collapse
 
mohamed24awwad profile image
M.Awwad

In addition to that NodeJS is just a referable variables to the C++ modules and functions.

Collapse
 
aritik profile image
Ritik Ambadi

Hey Jakub!
You're absolutely right about referring to the environment being Single-Threaded and not the language. The environment dictates the threading model and the language utilises it. However I thought it best for beginners to understand JS as a single-threaded language because afaik , there are no environments for JS that support multi-threading. Workers are a browser feature and it's not directly related to JS.

Collapse
 
rochucky profile image
Rodrigo Alves

God, this is a great post!!!

Collapse
 
lucaspsilveira profile image
Lucas Pacheco

As a previously PHP developer and currently C# developer, I did some development with JS, mostly on frontend, I would like to deep my knowledge into Backend Javascript. Just to have a second tool available

Collapse
 
aritik profile image
Ritik Ambadi

My brother works with PHP and says he appreciates the opinionated approach of Symfony but he gets the point of using NodeJS. He loved using Express to build an API recently. Can't wait to see his reaction when he uses Fastify.

Collapse
 
mayannaoliveira profile image
Mayanna Oliveira

thank you
I like it too much 👍

Collapse
 
macnick profile image
Nick Haralampopoulos

Nice article about my beloved language. One little clarification though. Although Javascript is an interpreted language, all modern browsers support JIT compilation which converts it to bytecodes hence its high performance.

Collapse
 
aritik profile image
Ritik Ambadi • Edited

Absolutely Nick. JIT makes JS much faster than it was some years ago but it still can't compete with statically typed compiled languages.
However I see a possible change with Web Assembly that can enhance existing JS projects. It's an exciting time to be alive.

Collapse
 
architg98 profile image
Archit Garg

Great Post, Thanks for sharing!

Collapse
 
iamharnad profile image
Krishna Haranath

thank you ritik

Collapse
 
trailblazer1902 profile image
Adegboyega Blessing Olamide

Wow. Tis amazing to see how you guys elicits knowledge form different positions.

Thanks to Mr Ritik who shared the post in the first place.

Collapse
 
absan profile image
Ansuman Behera

Thanks for sharing this :)