Math.clz32() Method with Example in JavaScript

JavaScript | Math.clz32() Method: Here, we are going to learn about the clz32() method of Math class in JavaScript with Examples.
Submitted by Shivang Yadav, on December 25, 2019

JavaScript | Math.clz32() Method

Math.clz32() is a function in math library of JavaScript that is used to find the number of leading zeroes in the 32-bit representation of the number. The method will return the numeric value which is the number of leading zeroes.

Syntax:

    Math.clz32(x);

Parameter(s):

  • x – represents a value whose number of leading zero bit in the 32-bit representation to be returned.

Return value:

The return type of this method is number, it returns the number of leading zero bit in the 32-bit representation of the number.

Technical Insights:

  • JavaScript version: ECMAScript 1
  • Browser support: Chrome, Internet Explorer, Mozilla, Safari, Opera mini

Values accepted: Integer, floating-point, numeric string.

Invalid Values: empty variable, empty array all will return NaN (Not a Number).

Example 1: Valid values for the method

console.log(Math.clz32(2));
console.log(Math.clz32(10.98));
console.log(Math.clz32(-198.23));
console.log(Math.clz32(0));
console.log(Math.clz32("734.18"));

Output

30
28
0
32
22

Example 2: Invalid values for the method.

console.log(Math.clz32(1 + 5i));
// Output: Uncaught SyntaxError: Invalid or unexpected token

JavaScript Math Object Methods »




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.