Best Website-BuildersBest Website-Builders
    What's Hot

    First female police officer in rural Michigan town says fellow cops relentlessly harassed and assaulted her

    March 25, 2023

    Tottenham Hotspur 1-5 Arsenal: Gunners maintain title by thrashing Spurs

    March 25, 2023

    Women's Six Nations: Wales open with bonus-point win over Ireland

    March 25, 2023
    Facebook Twitter Instagram
    Facebook Twitter Instagram
    Best Website-BuildersBest Website-Builders
    • Home
    • CSS

      How to optimize Next.js fonts with @next/font

      March 25, 2023

      RCMP Phone Tracking Continues Despite Privacy Concerns

      March 25, 2023

      OpenAI Reveals Redis Bug Behind ChatGPT User Data Breach Incident

      March 25, 2023

      CSS’s Ledenkov and Bostedt, UWS’ Meylan named All-American

      March 24, 2023

      IT and Computer Science Skills Introduce Students to the IT Industry – Muleshoe Journal

      March 24, 2023
    • Joomla

      Save Thousands On Web Hosting With iBrave, Now Only $86

      March 23, 2023

      In Vitro Transcription Services Market Analysis, Research Study with Shanghai Zhishuo Biotechnology Co., Yunzhou Biotechnology Co.

      March 23, 2023

      Current state of UK content management systems

      March 23, 2023

      Reseller Hosting Business: Important Q&A

      March 21, 2023

      Web Hosting: 8 Elements Every Entrepreneur Should Look For

      March 20, 2023
    • PHP

      Ja Morant’s suspension puts him in the spotlight

      March 25, 2023

      Kelly Ripa and Mark Consuelos’ marriage is horny

      March 25, 2023

      Naomi Osaka gives birth These are her pregnancy products she swears by.

      March 25, 2023

      Something to read or watch when you need a snack.

      March 25, 2023

      Gwyneth Paltrow says she never thought of countersuing for $1 in her ski crash lawsuit from Taylor Swift

      March 25, 2023
    • UX

      Iberia named world’s most punctual airline in January

      March 25, 2023

      Hungama launches the highly anticipated all-in-one app that seamlessly integrates music and movies for an unparalleled user experience.

      March 25, 2023

      Fort Worth All-Women’s Robotics Team Fights for State Title – NBC 5 Dallas-Fort Worth

      March 25, 2023

      Fort Worth All-Women’s Robotics Team Fights for State Title – NBC 5 Dallas-Fort Worth

      March 24, 2023

      Navigating Algorithms: Tips and Tricks for SEO Success | Recommended

      March 24, 2023
    • Web Builders
      1. Web Design
      2. View All

      What Comes First in Website Development — Design or Copy?

      February 2, 2023

      Modern Campus Honors Best Higher Education Websites of 2022

      February 2, 2023

      Premier SEO Consultant in Las Vegas, Nevada with Unparalleled Customer Service

      February 2, 2023

      Can Religious Freedom Be Saved? This group is racing the clock to teach America’s first freedom

      February 2, 2023

      How i Create New Google Account

      February 7, 2023

      CWT powers tools for meeting and event planners

      January 31, 2023

      Best Website Builder – Website Builders

      January 24, 2023

      Is There A Market For Rap-Themed Slot Games? – Rap Review

      January 19, 2023
    • WordPress

      New Pixel Tablet leak contains images of Pixel Stand accessories

      March 25, 2023

      Sonos Move 2 could arrive in the coming months

      March 25, 2023

      Businesses Worry About the Dark Web, But They Are Not Doing Much

      March 25, 2023

      Quordle today – Tips and Answers for Saturday March 25th (Game #425)

      March 25, 2023

      This $399 AMD-based One-Eyed PC Is One Of The Weirdest Designs I’ve Seen In 25 Years

      March 25, 2023
    • Realtoz
      • Our Other Sites
    • More News
    Best Website-BuildersBest Website-Builders
    Home » JavaScript engine and how it works
    JavaScript

    JavaScript engine and how it works

    websitebuildersnowBy websitebuildersnowMarch 22, 2022No Comments6 Mins Read
    Facebook Twitter LinkedIn Telegram Pinterest Tumblr Reddit WhatsApp Email
    Share
    Facebook Twitter LinkedIn Pinterest Email


    I recently started a series aimed at teaching web developers how JavaScript works and the various components that make the process of compiling and running code in JavaScript fast and simple.

    The first article in this series was an overview of JavaScript engines, call stacks, and runtime environments. Part 2 of this JavaScript tutorial series focuses on the internals of the JavaScript engine and reveals why JavaScript is no longer an interpreted programming language.

    In case you missed it or need a refresher, be sure to read the first part of the series, How JavaScript Works Behind the Scenes.

    What is a JavaScript engine

    A JavaScript engine is the program responsible for executing JavaScript code. All modern browsers come with their own version of his JavaScript engine, but the most popular is Google’s V8 engine of him. Google’s V8 engine supports not only Node.js, but also the Google Chrome browser. Node.js is a JavaScript runtime used to build server-side applications outside the browser.

    Below is a list of different JavaScript engines for each of the major internet browsers.

    • V8 – An open-source JavaScript engine developed by Google for Chrome
    • spider monkey – JavaScript engine that powers Mozilla Firefox
    • JavaScript core – An open-source JavaScript engine developed by Apple for Safari
    • rhino – An open-source JavaScript engine for FireFox maintained by the Mozilla Foundation
    • chakra – JavaScript engine for Microsoft Edge
    • jerry script – A JavaScript engine for the Internet of Things (IoT).

    Now that you know what a JavaScript engine is, you can take a deeper look inside and learn about the various components of JavaScript. In the next section, we’ll look at the engine behind it and how it compiles JavaScript code into machine code so that it can be executed.

    read: Top 10 AngularJS Alternatives

    How does JavaScript compilation and interpretation work?

    First, let’s understand the difference between a compiler and an interpreter. As web developers may know, computers only understand 0’s and 1’s (think of them as simple on/off switches). Therefore, all computer programs must eventually be translated into machine code. This task is performed using a process called compilation or interpretation. The following sections describe each of these processes.

    What is compilation in programming

    At compile time, the entire source code is converted into machine code at once. Machine code is written in portable files that can be run anywhere, regardless of platform or operating system. The code compilation process involves two steps. The first step builds the machine code and the second step runs it on your machine.

    Machine code execution occurs immediately after compilation. For example, all the applications you use on your computer today were originally compiled and ready to run on your computer.

    How JavaScript compilation works

    read: Overview of garbage collection in JavaScript

    What is Interpretation in Programming?

    On the other hand, during interpretation, the interpreter executes the source code, executing it line by line. Unlike compilation, which is a two-step process, interpretation involves reading and executing code. at the same timeOf course, the source code must be translated into machine language, but the translation of the code does not happen ahead of time, but just before execution.

    JavaScript interpretation example

    What is just-in-time compilation?

    JavaScript is a purely interpreted language. However, the problem with interpreted languages ​​is that interpreted programming languages ​​have much slower performance compared to compiled languages. This is a problem for modern applications that require fast processing and high performance. Imagine you’re playing an online game in your browser and moving a cube through the tiles takes seconds to reach the endpoint. Is such delay acceptable?

    Many people still refer to JavaScript as an interpreted programming language, but that is no longer the case. Current JavaScript engines use the concept of both compilation and interpretation at the same time. Just-in-time (JIT) compile.

    In this approach, the entire source code is compiled into machine language at once and then executed.still contains two steps Beforehand It compiles, but there is no portable file to run. This is much faster than running code line-by-line, making it the perfect solution for today’s fast-performance web applications. This inclusion of JIT compilation is why JavaScript is technically no longer an interpreted programming language.

    How does just-in-time compilation (JIT) work?

    So how does the JavaScript Just-in-Time compiler work? When a new piece of JavaScript code enters the JavaScript engine, the first step taken is parsing the code. During this process the code is parsed into a data structure called Abstract Syntax Tree (AST).

    The abstract syntax tree first splits each line of code into meaningful pieces for JavaScript. let me, staticAlso function keyword. Then save these codes in a tree-like structure. The next step is to check for syntax errors and if none are found, use the resulting tree to generate machine code.

    Now let’s look at a simple example of JIT in action. The following JavaScript code snippet declares a variable on the left and has its AST equivalent on the right.

    JIT compilation explained JavaScript JIT example

    here, constant named variable value given value 45As you can see on the .AST tree side, there is a lot of additional code beyond the declaration. Can you imagine all the extra code generated in a large application?

    The next step is to compile the generated AST into machine code. This machine code is then executed. This is how modern JavaScript uses just-in-time compilation. Note that the machine code execution process happens in the JavaScript engine’s call stack.

    JavaScript call stack

    So far so good. At this point the code is running and the process is finished. Not so fast – JavaScript has some code optimization strategies to implement. First, JavaScript creates very unoptimized machine code to make scripts run as fast as possible. Then, in the background, this unoptimized code is recompiled and optimized while the current code is running. This is done most of the time, after each cycle of optimization swapping unoptimized code for more optimized code without stopping execution. This is why the JavaScript engine works so fast.

    The code optimization process is done in a special thread separate from the main thread. JavaScript developers do not have access to code optimization algorithms from their source code. Different engines implement the strategy in different ways, but in a nutshell, this is how modern JavaScript just-in-time compilation works.

    read: HTML, CSS and JavaScript tools and libraries



    Source link

    Share this:

    • Tweet
    • Email
    • Pocket
    • Mastodon
    • WhatsApp
    • Telegram
    • Share on Tumblr
    • Print
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Telegram Email
    Previous ArticleRender HTML and CSS with ESP32
    Next Article Best Madness TV Sales for March 2023: 4K, OLED and QLED TV Deals
    websitebuildersnow
    • Website

    Related Posts

    Hackers Inject Weaponized JavaScript (JS) into 51,000 Websites

    March 25, 2023

    Four ways to remove specific items from a JavaScript array

    March 24, 2023

    Toolkit enables JavaScript developers to program embedded devices

    March 23, 2023
    Add A Comment

    Leave a Reply Cancel reply

    Top Posts

    Subscribe to Updates

    Get the latest sports news from SportsSite about soccer, football and tennis.

    Advertisement
    Demo

    This website provides information about CSS and other things. Keep Supporting Us With the Latest News and we Will Provide the Best Of Our To Makes You Updated All Around The World News. Keep Sporting US.

    Facebook Twitter Instagram Pinterest YouTube
    Top Insights

    First female police officer in rural Michigan town says fellow cops relentlessly harassed and assaulted her

    March 25, 2023

    Tottenham Hotspur 1-5 Arsenal: Gunners maintain title by thrashing Spurs

    March 25, 2023

    Women's Six Nations: Wales open with bonus-point win over Ireland

    March 25, 2023
    Get Informed

    Subscribe to Updates

    Get the latest creative news from FooBar about art, design and business.

    © 2023 bestwebsite-builders. Designed by bestwebsite-builders.
    • Home
    • About us
    • Contact us
    • DMCA
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.