JavaScript weakMap has() method is used to return a boolean value(true or false) which indicates whether an element with a specified key exists in the weakmap object or not.
Syntax
weakMap.has(key);
Parameters
key: The key of the element that is going to be tested for presence in the weakMap object.
Return Value
It returns a boolean value.
Example 1: How to Use JavaScript weakMap has() Method
let weakMap = new WeakMap();
let key1 = {};
let key2 = {};
weakMap.set(key1, 79);
weakMap.set(key2, 'askJavascript');
console.log(weakMap.has(key1));
console.log(weakMap.has(key2));
Output
true
true
Example 2
let weakMap = new WeakMap();
let key1 = {};
let key2 = {};
weakMap.set(key1, 79);
console.log(weakMap.has(key1));
console.log(weakMap.has(key2));
console.
Output
true
false
Browser Compatibility
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |
That’s it!
Related posts
JavaScript WeakMap set() Method
JavaScript WeakMap get() Method
JavaScript WeakMap delete() Method

Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both front-end and back-end development. His proficiency in the Python language stands as a testament to his versatility and commitment to the craft.