Introduction to JS

ZainDev
2 min readMay 18, 2021

What is JS?

  • JavaScript is a cross-platform, object-oriented scripting language used to make webpages interactive (e.g., having complex animations, clickable buttons, popup menus, etc.).
  • JavaScript is a lightweight interpreted language.

Scripting language

  • JavaScript is not a programming language in strict sense. Instead, it is a scripting language because it uses the browser to do the magic work. If you command an image to be replaced by another one, JavaScript tells the browser to go do it.
  • For example: BROWSER , DOM, GEOLOCATION and CANVAS APIS etc.

Interpreted VS Compiled

  • In interpreted languages, the code is run from top to bottom and the result of running the code is immediately returned.
  • You don’t have to transform the code into a different form before the browser runs it.
  • The code is received in its programmer-friendly text form and processed directly from that.
  • Compiled languages on the other hand are transformed (compiled) into another form before they are run by the computer.
  • For example, C/C++ are compiled into machine code that is then run by the computer.
  • The program is executed from a binary format, which was generated from the original program source code.

Interpreter works

The web browser receives the JavaScript code in its original text form and runs the script from that. From a technical standpoint, most modern JavaScript interpreters actually use a technique called just-in-time compiling to improve performance; the JavaScript source code gets compiled into a faster, binary format while the script is being used, so that it can be run as quickly as possible. However, JavaScript is still considered an interpreted language, since the compilation is handled at run time, rather than ahead of time.

Client-side VS Server-side

Client-side code is code that is run on the user’s computer — when a web page is viewed, the page’s client-side code is downloaded, then run and displayed by the browser.

Server-side code on the other hand is run on the server, then its results are downloaded and displayed in the browser. Examples of popular server-side web languages include PHP, Python, Ruby, ASP.NET and… JavaScript! JavaScript can also be used as a server-side language, for example in the popular Node.js environment.

JS Engine

In modern browsers we have JS engine. It takes our code and execute it.

  • Chrome use V8 engine
  • Mozilla FireFox use SpiderMonkey engine.
  • IE use Chakra engine
  • etc…

--

--

ZainDev

Software Engineer - Senior Full Stack Developer (Tech and Project Lead) ✓Angular ✓React ✓Next ✓Node ✓WebSocket ✓JavaScript ✓TypeScript