Found 6685 Articles for Javascript

How to compare two numbers in JavaScript?

Shubham Vora
Updated on 08-Aug-2022 09:02:40

16K+ Views

In this tutorial, we will learn to compare two numbers in JavaScript. If you are a competitive coder or application developer, in these cases, you need to make a comparison between two numbers and need to perform the particular operation basis on the comparison result of the numbers. Still, many programmers think we can compare the number only using the equality operator. Still, we can also compare the numbers using the less than or greater than operators. We will see the use of all three operators to compare the number in this tutorial. Using the Strict Equality Operator (===) In ... Read More

How to convert a String containing Scientific Notation to correct JavaScript number format?

Jennifer Nicholas
Updated on 17-Jun-2020 06:44:36

1K+ Views

To convert a string with Scientific Notation, use the Number function. Pass the value to this function.ExampleYou can try to run the following code to convert a string to correct number format −Live Demo                    document.write("String with Scientific Notation converted below:");          document.write(Number("7.53245683E7"));           OutputString with Scientific Notation converted below: 75324568.3

How to get the length of a Number in JavaScript?

Vrundesha Joshi
Updated on 17-Jun-2020 06:34:53

16K+ Views

Use the toString() method to covert the Number to string, then the length() method gives you length.ExampleYou can try to run the following code to learn how to get the length of a Number −Live Demo                    var num1 = 344;          var num2 = 149856;          document.write("Length of number "+num1+" = "+ num1.toString().length);          document.write("Length of number "+num2+" = "+ num2.toString().length);           OutputLength of number 344 = 3 Length of number 149856 = 6

How to make a Website step by step?

Ali
Ali
Updated on 15-Jun-2020 08:33:11

476 Views

A website is a group of a web page, which has content, images, videos, header, etc. It is with a unique domain name and published on the web server.DomainA domain is what you type on the web browser to open a website. For example www.qries.com, www.tutorialspoint.com, etc. The domain is uniquely defined for a website. Buy a domain name from domain name registrar and website hosting companies like GoDaddy.Here, you can see the domain name typed on the web browser:Hosting PackageThe website which you’re looking to develop will have content, images, documents, etc. For all these, you need space, which ... Read More

How to find the largest number contained in a JavaScript array?

Abhishek
Updated on 31-Oct-2022 07:57:15

11K+ Views

In this tutorial, we will learn about the different methods or ways of finding the largest number contained inside a JavaScript array. An array is a collection of different values. We will define an array of numbers in which we will search for the largest number. There are three ways of finding the largest number in a JavaScript array that is listed below − Traversing the Whole Array Using the reduce() Method Using the Math.max() and apply() methods Traversing the Whole Array This is the easiest or the most naive approach to find the largest number in the ... Read More

How to determine if a number is odd or even in JavaScript?

Shubham Vora
Updated on 02-Sep-2023 15:30:06

40K+ Views

In this tutorial, let’s see how to determine whether a number is odd or even using JavaScript. The first step is understanding the logic. What are even numbers? Even numbers will be exactly divisible by 2. The remainder will be zero. What are odd numbers? Odd numbers will carry a remainder when divided by 2. Using the if-else Condition and Modulo Operator "if" will check a condition, and the if block code will be executed if the condition is true. If the condition is false, else block code will be executed. The modulo operator in JavaScript returns the remainder. Syntax ... Read More

How to round up a number in JavaScript?

Prabhdeep Singh
Updated on 07-Nov-2022 07:57:31

748 Views

In this tutorial, we will discuss how to round up a number in JavaScript. There is a property in JavaScript under ‘Math’ named “ceil” with the help of this property we can easily round up a number in JavaScript. Ceil() is a mathematical function that computes an integer x to greater than or equal to x. If x has the decimal value zero or is a simple integer then it returns x, and if the number is a decimal number (x.yz, here yz is a non-zero number) then it returns x+1. Syntax var x = A.B var value = Math.ceil(x); ... Read More

How do you check that a number is NaN in JavaScript?

Krantik Chavan
Updated on 17-Jun-2020 06:30:40

178 Views

NaN is a JavaScript property, which is Not-a-Number value. This shows it is not a legal number. Here’s the syntax −SyntaxNumber.NaNTo find out whether a number is NaN, use the Number.isNaN() or isNan() method. Here’s an example to check −ExampleLive Demo           Check                      function display() {             var a = "";             a = a + isNaN(434) + ": 434";             a = a + isNaN(-23.1) + ": -23.1";             a = a + isNaN('Hello') + ": 'Hello'";             a = a + isNaN(NaN) + ": NaN";             a = a + isNaN('') + ": ''";             a = a + isNaN(0) + ": 0";             a = a + isNaN(false) + ": false";             document.getElementById("test").innerHTML = a;          }          

How to get a number of days in a specified month using JavaScript?

Nishtha Thakur
Updated on 17-Jun-2020 06:47:45

1K+ Views

To get numbers of days in a month, use the getDate() method and get the days.ExampleYou can try to run the following code to get a number of days in a month −Live Demo                 var days = function(month,year) {          return new Date(year, month, 0).getDate();       };       document.write("Days in July: "+days(7, 2012)); // July month       document.write("Days in September: "+days(9, 2012)); // September Month           OutputDays in July: 31 Days in September: 30

How can I round down a number in JavaScript?

Shubham Vora
Updated on 14-Jul-2022 12:06:17

994 Views

This tutorial teaches us to round down a number in JavaScript. The meaning of the round-down number is “returning the integer which is equal to or less than the current float number”.For example, if we round down the number 9.99, we get 9 as an output, and in the same way, for 8.01 we get 8 as an output. In simple terms, if you represent your current number in the number line, you must return the nearest integer that resides on the left side of the current number.In this tutorial, we will take a look at three different approaches to ... Read More

Advertisements