Learnitweb

Category: JavaScript tutorial

  • Create unmodifiable copy using copyOf method

    1. Introduction In Java 10, the Set.copyOf, List.copyOf, Map.copyOf static factory methods provide a convenient way to create unmodifiable collections (Set, List and Map). A collection is considered as unmodifiable if elements cannot be added, modified or removed. An unmodifiable collection hold the same data as long as the reference exists to the collection. The…

  • Web document origin

    1. Introduction In this tutorial, we’ll discuss what is a web document’s origin. Understanding a document’s origin is important while discussing other topics like CORS error and Window.localStorage. A document’s origin is defined by following three things of the URL used to access it: scheme (protocol). For example, http and https. hostname (domain). For example,…

  • WeakSet in JavaScript

    1. Introduction A WeakSet is a collection of unique objects and references to objects in a WeakSet are held weakly. The term weakly here means that if no other references to an object stored in WeakSet exist, those objects can be garbage collected. WeakSet can contain only objects. Since objects of WeakSet are held weakly…

  • void operator in JavaScript

    1. Introduction Sometimes the requirement is to evaluate an expression that produces a value at a place where the expected result is undefined. Or simply to say, you want to evaluate an expression and result as undefined, the void operator can be used in such case. The void operator evaluates the given expression and then…

  • static in JavaScript

    1. Introduction The static keyword is used to define static method, property or static initialization block for a class. A static method or property is accessed using the class name. A static method or static property can not be accessed using instance of the class. If a method or a property is not associated to…

  • Closure in JavaScript

    1. Introduction In this tutorial, we’ll discuss one of the most important concept of JavaScript – Closure. Closure is a popular interview question. Closure is not a special syntax and is not related to a particular class or library. You can think it as a concept. Closure is created as a result of writing code…

  • 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…