If you are new to the JS world, you may have assumed that it is a programming language, but it is STRICTLY NOT. It is simply a scripting language that has taken over the web world.
Huh? That's cool, right? Let's dive deep!
JS is a Lightweight, Interpreted, and Just-In-Time scripting language. We don't need any external compiler to convert it into machine code and get the output (just like JAVA). All we need is a browser and your script file.
Js is synchronous (i.e., step by step). It can only execute line by line. Some cool techies even use the term "JS is an event-driven language" which means everything will get happen based on events (i.e., onLoad, onClick, OnMouseOver, etc...)
Js is single-threaded, which means it can handle only one operation at a time. However, we can use the event-loop concept to give JS the superpower to perform asynchronously.
NOTE: Thanks to C++, most of the JS operations are extensively written in this low-level language. Don't think JS is capable to handle asynchronous activities under the hood C++ is helping us
How do I use the script?
All we need is an HTML file. We can add our script just above the closing section of the <body /> tag.
Think before you add! (Loading strategy)
Adding one script file is easy, but if you have multiple scripts, loading them in the right order is much more important.
Sometimes there may be a situation where script3.js code is dependent on script2.js considering this (if script3.js loads first before script2.js), then our application will crash!
To handle the situation we can make use of "async" and "defer"
ASYNC (default behavior): Here, our script will get executed as soon as it gets downloaded. There will be no control over the order we expect.
DEFER: If you want an ordered way to execute your code, then approach it this way.
Hey Devs!
Thank you very much if you came this far. I assume this blog has provided theoretical knowledge of JS. Please share if you find this interesting.