Hello guys, greetings from Vinit Parekh. I hope you are doing well. As you might know we can't imagine a web development without use Javascript. so in this article I decided to explain some concepts of JavaScript in simplified way.
So let's get started... ๐๐๐
1. Anonymous function:
An anonymous function is the function that doesn't have a name. This is important because it allows the function to be called without having to specify the function's name.
Syntax:
//Using function keyword
function() {
// executable code
}
(() => {
// executable code
})()
Example:
/*
This function executes itself after the delay of
1000 microsecond ( 1 second )
*/
setTimeout(() => {
console.log('Hello World');
}, 1000);
2. localStorage
localStorage is provided by Browser and it allows us to store data as key-value pairs in our web browser using an object. It can store the data upto 10 MB.
Basic Usage of localStorage
- SAVING data to localStorage using:
localStorage.setItem("key", "value");
- READING data from localStorage using:
var name = localStorage.getItem("key");`
- REMOVING data from localStorage using:
localStorage.removeItem("key");
3. sessionStorage
It is a mechanism that is used to save data in Browser. It stores only for the current website session. which means that it won't be accessible after closing the browser.
Basic Usage of sessionStorage
- Save data to sessionStorage
sessionStorage.setItem("key", "value");
- Get saved data from sessionStorage
let data = sessionStorage.getItem("key");
- Remove saved data from sessionStorage
sessionStorage.removeItem("key");
- Remove all saved data from sessionStorage
sessionStorage.clear();
4. Hoisting
"Hoisting" is the feature in JavaScript that allows you to move variables, functions and classes up one level in the call stack so that they are visible outside of the function. In simple words you can use variables before declaring them.
let
and const
variable can be hoisted to the top of the block, but not initialized.
Example:
name = "Vinit"
let name;
5. this Keyword
this
keyword refers to an object in Javascript. It refers to different objects depending on how it is used. Refer the video mentioned below.