Youssef William
4 Jan 2023
•
4 min read
We use Javascript frameworks like ReactJs, Angular, you name it, and before any technical interview, we make sure we remember the concepts of the library/framework we are familiar with but we neglect some of the core concepts of JavaScript.
At least that happened to me before, I planned for my interview by reviewing some React interview questions, remembering how to use useEffect
correctly “I always forget the clean-ups”, and a quick review useMemo
or useRef
that sometimes I don’t get my head around them. Until a certain time, I applied for a job 2 years ago and didn’t know the library/framework that I was going to be asked about in the tech interview. The interviewer was looking for a JavaScript engineer that can wrap his/her mind around any of the language’s frameworks. It didn’t go well and it was clear I need to work on understanding the core of JS.
In this article and the following ones, I'm going to tell you a brief on some core concepts an advanced javascript engineer should be familiar with.
There are two ways to transform code into machine language that is understandable by computers:
All languages have to be interpreted and compiled because it has to run “interpreted” and also it has to get translated to a lower-level language like machine code.
Browsers started mixing compilers to make engines faster, it’s having the best of both “Interpreter” and “Compilers”, by this way it improves the speed of executing the javascript code. That’s why JavaScript language is not only an interpretive language, it could be also compiled.
A call stack is a place to run and keep track of what’s happening line by line in our code and run it in order. It stores functions and variables as your code executes, and it runs in a First In Last Out mode, what is good about it is that it tells the engine where it stands in the code file, whatever is on the top of the call stack, that’s what javascript is running or executing.
While memory heaps store and write information, where we can store our variables and data, think of it as a free store javascript engine provides to store any kind of data in an unordered fashion.
And the real challenge, if you don’t understand what is the call stack or the memory heap, you can run into some serious problems that would show poor engineering skills like:
No, not the famous site you visit daily, it’s the big red error that pops in your console, with no clue what did you do wrong in order.
It happens when we keep trying to call functions nested inside of each other over and over again. Something like a recursive function without a success state or a return state.
// By this way, we would keep adding things to the stack more and more.
function inception(){
inception();
}
Memory leaks:
I’m sure you encountered this error before, maybe after checking whether you’re iterating correctly in your array of data, and it means you ran into an infinite loop.
let arrayOfTrials = [];
while(1) {
arrayOfTrials.push("hi");
}
Memory leaks don’t only happen on looping inside of an array but also in some unfamiliar cases like:
1. Keep adding variables to the environment as global variables will add more and more pieces of memory.
2. Adding event listeners to one of the elements in your document and never removing them when you don’t need them fills up your memory.
3. Using setInterval()
which is a method that continues calling the function until you clear it, and you forget about clearing it by using the clearInterval()
method.
JavaScript Engine itself is synchronous, one at a time, in order, only one thing can happen at a time. That’s different from JavaScript Runtime.
In the following up articles, I’m going to talk more about the JavaScript Runtime, the foundation of JavaScript, and much more advanced concepts.
Always return to the origin of the language you use in your framework or library, I know companies are looking for a specific field in frontends like a React Developer or an Angular2+ Engineer, but it’s always better to adjust yourself to a new library or framework, rather than working with a language you don’t understand its core.
Don’t put yourself as a framework engineer, dig deep, know why, and understand the concepts of a certain language, that’s when you can do powerful things!
Never forget, You can always depend on JavaScript.
Ground Floor, Verse Building, 18 Brunswick Place, London, N1 6DZ
108 E 16th Street, New York, NY 10003
Join over 111,000 others and get access to exclusive content, job opportunities and more!