Principles of JavaScript

Search for a command to run...

Jome Favourite, Good one. Thanks for sharing!
Side note, this is my first tech blog, I'm so excited
Wish you many more!
Thanks for reading.
You're welcome
I'm sharing what I've learnt from a course I took: "JavaScript: The Hard Parts v2" from [Frontend Masters](https://frontendmasters.com/courses/javascript-hard-parts-v2/) by Will Sentance.
Hello once again! This article is a more like a continuation from my first blog post, so I'll suggest you check it out first. Also, this article is written from the knowledge I've got from Javascript: The Hard Parts v2 and by also making researches ...
With the rise of AI agents, vibe coding, and the advancement of software development tools, it's never been easier to build applications quickly. However, these advancements come at a cost to software

Personal highlights along with Work highlights in 2024

π‘ Originally posted here. In the intricate world of web design today, typography serves as a powerful means of expression, improving site usability and it goes beyond the realms of font choice and sizes. In this article weβll explore a sub-section...

Ever spent hours wrestling with images that refuse to stay put in your web layouts? You're not alone. In this comprehensive guide, we will unravel the mystery behind different image centering methods, from the basic and widely used to the more advanc...

Tailwind CSS recently launched some awesome updates in v3.4, supporting CSS features like Dynamic viewport units, subgrid supports and other features, which we'll go over in this article. It's so easy to be carried away by using the already-known fea...

Hello everyone, In this article, I'll be sharing my jottings from a course I recently took from Frontend Masters : JavaScript: The Hard Parts, v2.
I'll be documenting what I've learnt throughout the course for reference later on and also sharing it with you guys.
Side note, this is my first tech blog, I'm so excited π.
I'll begin, by explaining how JavaScript execute and run code, which leaves us to the:
The term "Thread of Execution" simply means Javascript goes through the code line-by-line and then runs/execute each line as it goes. Which makes Javascript, a Synchronous Language.
Now you might wonder, what's Synchronous?
Synchronous simply means executing one instruction completely before moving to the next instruction.
Okay then, let's walk through this the code below:
var fruits = ["orange", "apple", "mango", "pineapple"]
hello everyone
fruits[3]
console.log(3)
Looking at the above example, if it were to be run on the browser's console. The first line is checked and valid cause Javascript recognizes that's that variable fruit that has an array as the value.
Meanwhile, as soon as line 2 is got to, instantly on the console you'll get :
Uncaught SyntaxError: Unexpected identifier
Hereby Javascript is saying, I don't know what you mean by hello everyone and then at line 3 -fruits[3]` isn't executed and any other statement below wouldn't be executed.
To sum up the discussion on Thread of Execution. Javascript goes through a code line-by-line and execute each line, if there's an error on a line like at line 2, from the above example any other Javascript statement valid or not below the error isn't going to be executed.
Try it for yourself
There're two expects to the Memory, which are:
And all the Memory does is to save data like strings and arrays even functions, so we can use that data later in its memory.
For example, we have an array:
var fruits = ["orange", "apple", "mango", "pineapple"]
Then the variable fruits is stored as a label/placeholder name on the Memory containing an array. So whenever we need the variable fruits we'll making a reference to the array stored in Memory.
Here's a visual view of how the variable is stored in Memory:
fruits: ["orange", "apple", "mango", "pineapple"]
Note: this example is being stored on the Global Memory.
Every line of code/instruction written that's not executed in a function is stored on the Global Memory. That's why the variable fruits declared earlier is stored on the Global Memory from the above example.
Before I dive into Local Memory, let's look at the code below:
function adding(num) {
var name = "Favourite";
let age = 30;
return num + 2
}
adding(4) //Output : 6
A function adding has been declared/defined and stored on the Global Memory.
Virtualized like this :
adding: function
When the function adding(4) is called on line 6, an Execution Context is created which will be discussed in the next article. Also, a Local Memory is created to store data that exist in the function body only.
The Thread of Execution which executes the code/instructions line-by-line goes into the function body adding and execute each line.
Line one (1) in the function body adding
var name = "Favourite";
Representation in memory:
name: "Favourite"
The variable name is a placeholder name/reference in memory that has the value "Favourite". And so on for the rest lines irrespective of var and let in the function body.
A more precise illustration of what's stored on the Local Memory is shown below:
num: 4
name: "Favourite"
age: 30
Note: I'm not 30 years old π and the returned value isn't stored on the memory.
From the illustration above the parameter num in the function adding is being assigned a value 4 which is the argument passed and stored first on the Local Memory before anything else.
Then name and age.
Now the Thread of Execution is at line 3 in the function body adding which return a value return num + 2 .
4 + 2 = 6 ... outputs 6 to the console.
After all the lines of code in the function adding body has been executed, that function forgets its parameter value and anything stored in the Local Memory until invoked/called again and then a new argument will be passed to the function or not.