Node.js util.isDeepStrictEqual() Method Last Updated : 28 Jul, 2020 Comments Improve Suggest changes Like Article Like Report The "util" module provides 'utility' functions that are used for debugging purposes. For accessing those functions we need to call them (by 'require('util')'). The util.isDeepStrictEqual() (Added in v9.0.0) method is an inbuilt application programming interface of the util module which is an exported type function that tests the deep equality of two values that is, between the actual (value1) and expected (value2) parameters. Deep equality is a method that helps to evaluate the enumerable "own" properties of child objects recursively by a few rules. Syntax: const util = require('util'); util.isDeepStrictEqual(val1, val2); Parameters: This function accepts two parameters as mentioned above and described below: val1 <any>: Any variable, Class, Function, Object, or JavaScript primitive. val2 <any>: Any variable, Class, Function, Object, or JavaScript primitive. Return Value <boolean>: If value1 and value2 are deemed equal then returns true, otherwise returns false. Example 1: Filename: index.js javascript // Node.js syntax to demonstrate the // util.isDeepStrictEqual() method // Importing util library const util = require('util'); // Creating object1 const object1 = { alfa: "beta", romeo: [10, 20] }; // Creating object2 const object2 = { alfa: "beta", romeo: [10, 20] }; // Returns false console.log("1.>", object1 == object2) // Returns true console.log("2.>", util .isDeepStrictEqual(object1, object2)) // Creating a fake date const wrongDateType = {}; // Comparing wrongDateType with correct date console.log("3.>", util.isDeepStrictEqual( wrongDateType, Date.prototype)); const anObject = {}; // Prototype is not same console.log("4.>", util.isDeepStrictEqual( anObject, wrongDateType)); // Returns false // Creating new date const newDate = new Date(); // Comparing Date formats console.log("5.>", util.isDeepStrictEqual( newDate, wrongDateType)); // Returns false const weakMapOne = new WeakMap(); const weakMapTwo = new WeakMap([[{}, {}]]); // Comparing two weakMaps console.log("6.>", util.isDeepStrictEqual( weakMapOne, weakMapTwo)); // Returns true Run index.js file using the following command: node index.js Output: 1.> false 2.> true 3.> true 4.> true 5.> false 6.> true Example 2: Filename: index.js javascript // Node.js syntax to demonstrate the // util.isDeepStrictEqual() method // Importing util library const util = require('util'); // String and integer are compared // wrong 1 !== '1'. console.log("1.>", util .isDeepStrictEqual({ a: 1 }, { a: '1' })); // Returns false // Comparing Not a Number with Not a Number console.log("2.>", util.isDeepStrictEqual(NaN, NaN)); // Returns true // Unwrapped numbers are different console.log("3.>", util .isDeepStrictEqual(Object(1), Object(2))); // Returns false // Directly importing isDeepStrictEqual method const { isDeepStrictEqual } = require('util'); // Unwrapped strings are same console.log("4.>", isDeepStrictEqual( Object('alfa'), Object('alfa'))); // Returns true // Comparing both negative values console.log("5.>", isDeepStrictEqual(-0, -0)); // Returns true // Same Value Comparison with different sign console.log("6.>", isDeepStrictEqual(0, -0)); // Returns false Run index.js file using the following command: node index.js Output: 1.> false 2.> true 3.> false 4.> true 5.> true 6.> false Reference: https://nodejs.org/api/util.html#util_util_isdeepstrictequal_val1_val2 Comment More infoAdvertise with us Next Article Node.js util.deprecate() Method A amitkumarjee Follow Improve Article Tags : JavaScript Web Technologies Node.js Node.js-util-module Similar Reads Node.js Utility Module The util module in Node.js provides a variety of utility functions that assist with tasks such as debugging, formatting, and inheritance. It includes methods for inspecting objects, formatting strings, and extending classes. Node.js Utility ModuleThe util module offers essential utilities that are n 4 min read Node.js util.callbackify() Method The util.callbackify() method is an inbuilt application programming interface of the util module which is used to run an asynchronous function and get a callback in the node.js.Syntax:Â Â util.callbackify( async_function ) Parameters: This method accepts single parameter as mentioned above and descri 2 min read Node.js util.debuglog() Method The âutilâ module provides âutilityâ functions that are used for debugging purposes. For accessing those functions we need to call them (by ârequire(âutilâ)â). The util.debuglog() (Added in v0.11.3) method is an inbuilt application programming interface of the util module which is used to create a f 3 min read Node.js util.format() Method The util.format() (Added in v0.5.3) method is an inbuilt application programming interface of the util module which is like printf format string and returns a formatted string using the first argument. The formatted string contains zero or more format specifiers in which the corresponding argument v 5 min read Node.js util.inherits() Method The âutilâ module provides âutilityâ functions that are used for debugging purposes. For accessing those functions we need to call them (by ârequire(âutilâ)â). The util.inherits() (Added in v0.3.0) method is an inbuilt application programming interface of the util module in which the constructor inh 3 min read Node.js util.formatWithOptions() Method The util.formatWithOptions() (Added in v10.0.0) method is an inbuilt application programming interface of the util module which is like printf format string and returns a formatted string using the first argument. It is somewhat identical to util.format() method, the exception in this method is that 4 min read Node.js util.inspect() Method The "util" module provides 'utility' functions that are used for debugging purposes. For accessing those functions we need to call them by 'require('util')'. The util.inspect() (Added in v0.3.0) method is an inbuilt application programming interface of the util module which is intended for debugging 7 min read Node util.promisify() Method `util.promisify()` in Node.js converts callback-based methods to promise-based, aiding in managing asynchronous code more cleanly. This alleviates callback nesting issues, enhancing code readability, and simplifying asynchronous operations through promise chaining.Syntax:util.promisify(func)Paramete 2 min read Node.js util.isDeepStrictEqual() Method The "util" module provides 'utility' functions that are used for debugging purposes. For accessing those functions we need to call them (by 'require('util')'). The util.isDeepStrictEqual() (Added in v9.0.0) method is an inbuilt application programming interface of the util module which is an exporte 3 min read Node.js util.deprecate() Method The util.deprecate() (Added in v0.8.0_ method is an inbuilt application programming interface of the util module which wraps fn (which may be a function or class) in such a way that it is marked as deprecated. When util.deprecate() method is called, it returns a function that emits a DeprecationWarn 3 min read Like