A tour of JavaScript Engine and why you should write JS code that looks like statically typed

2. Node by default has v8 engine but there are packages, by which you can use chakra engine with node. Generally for IOT devices, we sacrifice performance of JS engine owing to small memory capacity and use smaller engines like DuckTape or JerryScript

3. We know JS is dynamically typed, that means we do not need to tell in advance when we define var x; what type x variable is, we can either store integer or string or Boolean in it, on the other hand in C++, we need to define int x; beforehand so that the compiler knows the type of variable. This object type determination is an overhead that JS compiler has and C++ compiler does not

4. For the following code

JS engine will do JIT compilation and execute the code, but JS engine has optimizing compiler module in it, which tries to produce optimized machine level code for hot functions i.e. functions which are run many times

5. Thus along with JIT compilation, JS engine also creates optimized machine code and next time it encounter this hot function it will not do JIT compilation, but use the optimized code already created

6. But here is a caveat, this optimized machine level code is dependent of input arguments to the function, so if the same type of object is passed to the hot function, then only optimized code can be used otherwise JS engine has to again compile the code JIT

7. What is same type of object for compiler

compiler’s view of object similarity

8.So the advice for JavaScript developers would be write a code that looks like statically typed

Reference: JavaScript Engines Overview…. How do they work?

--

--

--

I love learning

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Designing with API data in 10 minutes

How React Native boilerplate helps us build mobile apps faster

Adventures in Regular Expression — JS Edition

Lazy Load Images in Angular with Two Lines of Code

[Part 1]Building a micro-frontend application: Why do it and what is single-spa?

How to Create Pages Dynamically in Gatsby Using MDX

Storing Login Information With Cookies (JavaScript)

Onsen UI Framework — Build Hybrid & Mobile Apps

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Akshay Jain

Akshay Jain

I love learning

More from Medium

You Don't Know JS: Up and Going Summary

It’s All In The Mindset: How Playing Resident Evil Taught Me To Be A Better Beginner…

ReactJS vs Angular: which is better for your website?

JavaScript, Best Practice and Chrome Updates