Learnitweb

Category: JavaScript tutorial

  • Set in JavaScript

    1. Introduction Set is a collection of unique values. Value in the Set can be primitive value or object reference. Values in Set can be iterated in the insertion order.Each value in the Set is unique so a value will not be found twice in the Set. 2. Value equality The values in the Set…

  • Map in JavaScript

    Map is a collection of key value pairs. Map allows both primitive and objects as key or value. Map at first looks like an object which also holds key value pairs, but it is different than object.

  • Lexical scope in JavaScript

    A lexical scope is a scope that is defined at lexing time. In other words, lexical scope is based on where variables and blocks of scope are written. Let us understand this with the help of an example. There are three nested blocks in this code. The global scope, which has one identifier outerFunction. The…

  • Double not (!!) in JavaScript

    Double not (!!) is used to convert any value to its corresponding boolean primitive. That is, a truthy value to primitive true and a falsy value to primitive false. The conversion is based on the truthy and falsy value of the operand used with double not (!!). How it works? In first step, first not…

  • Falsy in JavaScript

    1. Introduction While writing JavaScript programs, it is not mandatory for you to provide only true or false in Boolean context. For example, you can use a number or a string as a condition in if: A falsy value is a value that is considered false in a Boolean context. JavaScript uses type coercion to…

  • generator and generator function in JavaScript

    1. Introduction Regular functions return a single value which could be primitive or object. A regular function can not be used to return multiple values based on demand. Generators can do that. A Generator can be used to create a data stream. A Generator will return a value based on a certain logic, each time…

  • getter in JavaScript

    1. Introduction Sometimes, you may to access a property which is dynamically calculated. However, you can do this with the help of a method, but you are not willing to use a method. In such case, you can use get syntax. Let us understand this with the help of an example. Suppose there is an…

  • Object.freeze() in JavaScript

    1. Introduction In this tutorial, we’ll discuss freeze() method of Object. The freeze() method freezes an object. Frozen object here means: new properties can not be added to a frozen object. existing properties can not be removed. values of existing properties of a frozen object can not changed. the prototype of a frozen object can…

  • Introduction to JavaScript Promise

    1. Introduction Suppose you ordered a burger in a restaurant. The cashier will take your order and will promise you that the burger will be delivered. After some time once the burger is available, your burger will be delivered. It is also possible that the burger will not be delivered due to some problem. The…

  • JavaScript Optional Chaining Operator (?.)

    1. Introduction The optional chaining operator (?.) enables you to read the property within a chain of connected objects without specifically checking each reference in the chain for null or undefined. The ?. operator short-circuits the chain and returns undefined if any reference in the chain is nullish (null or undefined). The behavior of ?.…