Javascript MOST Important Concepts everyone should know

Tasadduq Ali
2 min readJan 21, 2023

--

Today we are going to talk about the most essential JavaScript Concepts

First of all, if you are interested in joining our Free session to answer your coding, career questions. Kindly fill out this form to join the community of CODE Culture Pro https://forms.gle/kjU3PWhwQy16Tghe9

Scope

Scope determines the accessibility of variables, objects, and functions.

In Javascript, a variable has 3 types of scope:

a. Block Scope
b. Function Scope
c. Global Scope

Hoisting
Hoisting in Javascript is a behavior in which a function or variable can be used before declaration.
In terms of the variable and constant keyword var is hoisted, and let and const do not allow hoisting.

Closures

A closure is a function that remembers the variables in its surrounding scope, even when the function is executed outside of that scope.

Code

function makeCounter() {
let count = 0;
return function() {
return count++;
};
}
let counter = makeCounter();
console.log(counter()); // 0
console.log(counter()); // 1
console.log(counter()); // 2

Callbacks

A callback is a function that is passed as an argument to another function and is executed after the first function is done.

Code

function add(a, b, callback) {
let result = a + b;
callback(result);
}

add(2, 3, function(result) {
console.log(result); // 5
});

Promises

A promise is a way to handle asynchronous operations in JavaScript. It represents a value that will be available in the future, either as a result or an error.

Code

let promise = new Promise(function(resolve, reject) {
setTimeout(function() {
resolve(“Hello, World!”);
}, 1000);
});

promise.then(function(value) {
console.log(value); // “Hello, World!”
});

If you have any questions about the coding just do let me know on Instagram or at codeculturpro@gmail.com

--

--

Tasadduq Ali
Tasadduq Ali

Written by Tasadduq Ali

I am MERN Stack developer working in UAE Govt to digitize their massive services. I will help you to become highly skilled Coder 😉

No responses yet