How to check first number is divisible by second one in JavaScript ? Last Updated : 08 Dec, 2021 Comments Improve Suggest changes Like Article Like Report Given two numbers and the task is to check the first number is divisible by the second number or not with the help of JavaScript. Before getting into the coding part, first let us know about the modulo operator and triple equals. To find a number is divisible by another or not, we simply use the reminder operator and if remainder is 0 then it is divisible otherwise not divisible. Example: variable a = 10; variable b = 5; if ((a % b) == 0) { // a is divisible by b else { //a is not divisible by b } We have used "==" operator for comparing the value of expressions. But when it comes to JavaScript we use "==="(Triple equals). Reason to use Triple equals: The triple equal sign tests for strict equality between two values. Both the type and the value you’re comparing have to be exactly the same. Examples of strict equality: 4 === 4 // true (Both numbers, equal values) 'gfg' === 'gfg' // true (Both Strings, equal values) 54 === '54' // false (Number compared with String) The double equal tests for loose equality and performs type coercion. It means we compare two values after converting them to a common type. Example: 3 == '3' // true Hence , we use "==="(Triple equals) in JavaScript rather than "=="(Double equals). Example: This is the code to check if the first numeric argument is divisible by the second one in JavaScript. HTML <!DOCTYPE html> <html> <body style="text-align:center;"> <h1 style="color:green;"> GeeksForGeeks </h1> <p> Enter first number: <input type="text" id="txt1" name="text1"><br> <br> Enter second number: <input type="text" id="txt2" name="text2"><br> <br> <button onclick="myFunction()">Divide</button> </p> <p id="demo" style="font-size: 20px; font-weight: bold;"> </p> <script> function myFunction() { var a = Number(document.getElementById("txt1").value); var b = Number(document.getElementById("txt2").value); const isDivisible = (dividend, divisor) => dividend % divisor === 0; if (a % b === 0) { document.getElementById("demo").innerHTML = a + " is divisible by " + b; } else { document.getElementById("demo").innerHTML = a + " is not divisible by " + b; } } </script> </body> </html> Output: Hence, this is how you can check if the first numeric argument is divisible by the second one or not in JavaScript. Comment More infoAdvertise with us C code_blooded7 Follow Improve Article Tags : JavaScript Web Technologies HTML-Tags JavaScript-Methods JavaScript-Questions +1 More Similar Reads How to convert a value to a safe integer using JavaScript ? In this article, we will learn How to convert a value to a safe integer using JavaScript. We have given a number, and we have to convert it into a safe integer using JavaScript. Safe Integers are integers between -(253 - 1) and (253 - 1). Approach: First, we take input using the prompt in JavaScript 2 min read How to add float numbers using JavaScript ? Given two or more numbers the task is to get the float addition in the desired format with the help of JavaScript. There are two methods to solve this problem which are discussed below: Table of Content Using parseFloat() and toFixed() method Using parseFloat() and Math.round() method Using Number() 2 min read Calculate current week number in JavaScript Calculating the current week number involves determining which week of the year the current date falls into. The method of calculation can vary slightly depending on the rules you follow, such as which day starts the week (Sunday or Monday) and how the first week of the year is defined.For example:J 2 min read How to Convert a Float Number to the Whole Number in JavaScript? Given a float number and the task is to convert a float number to a whole number using JavaScript. Below are various methods to convert float numbers to whole numbers in JavaScript:Table of ContentMath.floor (floating argument)Math.ceil (floating argument) Math.round (floating argument)Math.trunc (f 4 min read How to convert Number to Boolean in JavaScript ? We convert a Number to Boolean by using the JavaScript Boolean() method and double NOT operator(!!). A JavaScript boolean results in one of two values i.e. true or false. However, if one wants to convert a variable that stores integer â0â or â1â into Boolean Value i.e. "false" or "true". Below are 2 min read Convert a Number to a String in JavaScript These are the following ways to Convert a number to a string in JavaScript:1. Using toString() Method (Efficient and Simple Method)This method belongs to the Number.Prototype object. It takes an integer or a floating-point number and converts it into a string type.JavaScriptlet a = 20; console.log(a 1 min read Convert a negative number to positive in JavaScript In this article, we will see how we can convert a negative number to a positive number in JavaScript by the methods described below. Below are the methods to convert a negative number to a positive in JavaScript: Table of Content Multiplying by -1Using Math.abs()adding a minus signFlipping the bitUs 4 min read Check a Number is Prime or Not Using JavaScript A prime number is a whole number greater than 1, which has no positive divisors other than 1 and itself. In other words, prime numbers cannot be formed by multiplying two smaller natural numbers. For example:2, 3, 5, 7, 11, and 13 are prime numbers.4, 6, 8, 9, and 12 are not prime numbers because th 5 min read JavaScript - Convert a Number into JS Array You have a number, like 12345, and you need to convert it into an array where each element represents a digit of the number. For example, 12345 should become [1, 2, 3, 4, 5]. How can you achieve this in JavaScript?In JavaScript, there are various ways to transform a number into an array of its digit 3 min read How to generate a n-digit number using JavaScript? The task is to generate an n-Digit random number with the help of JavaScript. You can also generate random numbers in the given range using JavaScript. Below are the approaches to generate a n-digit number using JavaScript: Table of Content Using Math.random()Math.random() Method and .substring() Me 2 min read Like