JavaScript WeakSet has() method - JavaScript Tutorial

JavaScript WeakSet has() method

BLUF: This tutorial on JavaScript WeakSet has() method provides an in-depth look at JavaScript's core features. It includes practical examples and code snippets to help you master modern JS development.
Key Discovery: JavaScript WeakSet has() method

Understanding JavaScript WeakSet has() method is crucial for building dynamic, interactive web applications. Explore the examples below to see it in action.

The has method of the JavaScript WeakSet determines if a specific object exists within the WeakSet instance. It will return true if the given object is found, and false if it is not present.

Syntax

The syntax for the has method is illustrated as follows:

Example

weakSetObj.has(value)

Parameter

value - It represents the object to be searched.

Return

A Boolean value.

JavaScript WeakSet has method example

Let us examine an illustration to ascertain if the WeakSet object includes the designated object.

Example

<script>

var ws = new WeakSet();

var obj1={};

var obj2={};

ws.add(obj1);

document.writeln(ws.has(obj1)+"<br>");

document.writeln(ws.has(obj2)+"<br>");

document.writeln(ws.has());

</script>

Output:

Output

true

false

false

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience