Category: JavaScript tutorial
-
Scope in JavaScript
1. Introduction The scope is a general concept in the field of computer science that refers to the parts of the program where a particular variable, function, etc., can be accessed. In other words, the scope of an identifier (variable, function, etc.) is the part of a program where it is visible or can be…
-
Execution Context in JavaScript
1. Introduction In JavaScript, code is executed and is related to two main types of executions contexts. In this tutorial, we’ll discuss these two execution contexts: There is third type of execution context that is created for the code inside the eval function. Since the use of eval function is discouraged due to security concerns,…
-
HashSet in Java
1. Introduction In this tutorial we’ll discuss HashSet class of the Java Collections Framework. HashSet class is in java.util package in java.base module. HashSet class implements the Set interface, backed by a hash table (actually a HashMap instance). Following are the features of HashSet: Here is an example of HashSet: Output 2. Creating HashSet HashSet…
-
Java carrier thread example
1. Introduction In this short tutorial, we’ll see an example of carrier thread in Java. We’ll see with an example that carrier threads work on different tasks in case of virtual threads. 2. Example of Platform thread working on tasks In this example, we are creating and starting platform threads. We are using sleep() method…
-
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…