JavaScript WeakMap has() method - JavaScript Tutorial

JavaScript WeakMap has() method

BLUF: This tutorial on JavaScript WeakMap 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 WeakMap has() method

Understanding JavaScript WeakMap 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 WeakMap determines if the specified key exists within the WeakMap instance. It yields true if the key is found, and false if it is not present.

Syntax

The syntax for the has method is expressed as follows:

Example

WeakMapObj.has(key)

Parameter

key - It represents the key to be searched.

Return

A Boolean value.

JavaScript WeakMap has method example

Let’s examine an example to ascertain if the WeakMap object includes the given key.

Example

<script>

var wm = new WeakMap();

var obj1 = {};

var obj2 = {};

var obj3= {};

wm.set(obj1, "jQuery");

wm.set(obj2, "AngularJS");

wm.set(obj3,"Bootstrap");

document.writeln(wm.has(obj2));

</script>

Output:

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