Some Javascript Advanced Concept

mahin678

Mahin Tazuar

Posted on January 29, 2022

Some Javascript Advanced Concept

Image description

NameSpace-

we know javascript variable naming is very important for us. because if match same name variable javascript give an error and not code execute. NameSpace Concept's main purpose is to write unique variables. And many developers use different techniques like IIFE, using objects to create variables.

var yourNamespace = {

    foo: function() {
    },

    bar: function() {
    }
};
...
yourNamespace.foo();
Enter fullscreen mode Exit fullscreen mode

https://stackoverflow.com/questions/881515/how-do-i-declare-a-namespace-in-javascript
ref-https://youtu.be/PZQQhirc448

Recursion -

Recursion definition is, which function calls itself inside his code and stop it when the purpose is solved. This function rule is every time need to define how many times execute the function otherwise execute the function infinitely. Because this function calls itself inside the code this calling continuously works if does not stop with the condition.

function countDown(n) {
    if (n == 0) {
    return 0;
    }else {
   return  countDown(n - 1)+n;
    }
}
console.log(countDown(3));
Enter fullscreen mode Exit fullscreen mode

Garbage collection -

When we have defined a variable or code. Javascript saves this browser memory under a reference name. Sometimes we define many variables or something. But if we do not use this our code javascript finds out this code and removes it from the memory and another new variable assigns this memory space. Another thing is when a function uses this variable or reference value after the function execution javascript destroys the function or variable. So this whole this control javascript and that system called javascript Garbage collection.
The Garbage Collection mechanism in JavaScript is governed by two algorithms which are listed below.
1- Reference Counting Algorithm
2- Mark and Sweep Algorithm
ref-https://youtu.be/nRcoO1PEJMc?list=PLv2W1EeZUbo7A6fTAmd1vST7R-dr4KUdO

💖 💪 🙅 🚩
mahin678
Mahin Tazuar

Posted on January 29, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related