

{"id":65388,"date":"2019-08-02T18:06:16","date_gmt":"2019-08-02T12:36:16","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=65388"},"modified":"2021-02-17T21:32:26","modified_gmt":"2021-02-17T16:02:26","slug":"javascript-numbers","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/javascript-numbers\/","title":{"rendered":"JavaScript Numbers &#8211; Get Skilled in the implementation of its Methods!"},"content":{"rendered":"<p>We use numbers to count, measure and label. We\u2019ve been learning about them since playschool and we still use them as adults. We deal with numbers in our everyday life, may it be our finances, our scores or some calculations. They never leave our side, whether we like it or not. Thus it isn\u2019t possible that we learn JavaScript without learning about numbers.<\/p>\n<p>Going forward in our journey of JavaScript DataFlair Tutorial Series, this article will focus on all the aspects of JavaScript Numbers. We will learn the different methods to write a number and convert data types into numbers in JavaScript.\u00a0But before that, we would strongly recommend you to go through our previous tutorial on <a href=\"https:\/\/data-flair.training\/blogs\/javascript-boolean\/\"><em><strong>JavaScript Boolean<\/strong><\/em><\/a>. It will help you in better understanding of the concept.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-Numbers.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-66198 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-Numbers.jpg\" alt=\"JavaScript Number Methods\" width=\"802\" height=\"420\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-Numbers.jpg 802w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-Numbers-150x79.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-Numbers-300x157.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-Numbers-768x402.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-Numbers-520x272.jpg 520w\" sizes=\"auto, (max-width: 802px) 100vw, 802px\" \/><\/a><\/p>\n<p>After knowing what JavaScript Booleans are, let&#8217;s start with the tutorial on JavaScript Numbers.<\/p>\n<h2>What are JavaScript Numbers?<\/h2>\n<p>The number type in JavaScript represents <em>integers, floating-point-values, hexadecimal, octal and exponential values<\/em>. The script stores all the JavaScript numbers in <strong>64-bit<\/strong> format IEEE-754 standard, also called <strong>\u201cdouble-precision floating-point numbers\u201d<\/strong>. The number is stored in memory in the following manner:<\/p>\n<ul>\n<li><strong>Value<\/strong>: 52 bits (0-51)<\/li>\n<li><strong>Exponent<\/strong>: 11 bits (52-62)<\/li>\n<li><strong>Sign<\/strong>: 1 bit (63)<\/li>\n<\/ul>\n<h3>Different Methods to Write a Number in JavaScript<\/h3>\n<p>There are various approaches to write a number in JavaScript. Some of them are explained below with examples:<\/p>\n<p><strong>1. For Large Numbers<\/strong><\/p>\n<p>Suppose you are working on a JavaScript application for a bank\u2019s database management. There are millions of numbers you need to wade through and not all of them are small. Imagine having to write <strong>\u20b910,00,000<\/strong> for every transaction of <strong>10 lacs<\/strong>. And you can\u2019t even insert any commas between the numbers, so keeping track of the numbers is almost impossible and if tracked, it&#8217;s a tedious process, isn\u2019t it? Also, it creates opportunities for serious errors that you can\u2019t afford. We prefer to write<strong> 10 lacs<\/strong> and guess what, we can help JavaScript do that too! We can also shrink and represent the time required to finish the transactions, say<strong> 0.002<\/strong> <strong>seconds<\/strong>, making our application a lot more efficient.<\/p>\n<p>You can shorten the number by simply appending the letter <strong>\u201ce\u201d<\/strong>, followed by the number of zeroes after it. Let\u2019s use this technique to test different values in the browser console.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">var million = 1e6;\t\/\/1 and 6 zeroes (one million)\r\nvar milliseconds = 2e-3;\t\/\/5 zeroes to the left from 2<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-large-number.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"img-gray-border aligncenter wp-image-66182 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-large-number.jpg\" alt=\"JavaScript large number\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-large-number.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-large-number-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-large-number-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-large-number-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-large-number-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-large-number-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><strong>2. hex, octal and binary numbers<\/strong><\/p>\n<p>Hexadecimal numbers are very common to represent <em>colors, memory locations, encode characters, etc.<\/em> <a href=\"https:\/\/en.wikipedia.org\/wiki\/JavaScript\">JavaScript<\/a> supports octal and binary numbers, though not as widely used. The short number representation of <em>hex, octal and binary numbers<\/em> are the prefixes <strong>0x, 0o<\/strong> and <strong>0b<\/strong> respectively, followed by the number.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">var decimal = 157 \/\/ decimal number\r\n0x9D \/\/hexadecimal number\r\n0o235 \/\/octal number\r\n0b10011101 \/\/binary number<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-HexOctal.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"img-gray-border aligncenter wp-image-66183 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-HexOctal.jpg\" alt=\"JavaScript Hex,Octal\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-HexOctal.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-HexOctal-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-HexOctal-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-HexOctal-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-HexOctal-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-HexOctal-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><strong>3. The parseInt() and parseFloat() methods<\/strong><\/p>\n<p>The <strong>parseInt()<\/strong> and <strong>parseFloat()<\/strong> methods in JavaScript provide the programmer with the facility to extract the numeric values from a given value. In every transaction, the time required is in form <strong>2ms (0.002 seconds)<\/strong>. But to perform the needed calculations, we have to separate the value from the unit. For an efficient banking application, it is essential since we work on the actual numbers, excluding the unit.<\/p>\n<p>The <strong>parseInt()<\/strong> and <strong>parseFloat()<\/strong> methods help us to achieve this task by extracting integers and floating-point numbers from the given value. The methods do it by reading the value, from left to right. While the <strong>parseInt()<\/strong> method returns the integer and stops reading the value after getting a non-number value, the<strong> parseFloat()<\/strong> method continues its work even after the first point. It then returns the floating-point value (with a single point) and skips everything after the floating-point data it needed.<\/p>\n<p>The syntax for the <strong>parseFloat()<\/strong> method is as follows:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">parseFloat(string)<\/pre>\n<p>The syntax of the parseInt() method looks like this:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">parseInt(string, ?radix)\r\n\r\n<\/pre>\n<p>Why the second parameter? The optional parameter<strong> (radix)<\/strong> specifies the base of the numeral system, allowing us to extract numeric data from values with different bases too.<\/p>\n<p>Let us see these methods in action; open up your console and get started with the code below.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">var time = '2e-3s'\r\nparseFloat(time)\t\/\/time in seconds\r\n\/\/ 0.002\r\nparseInt(time) \/\/time in milliseconds\r\n\/\/ 2\r\nparseInt('9d', 16)\t\/\/extracting the number's base 16 equivalent\r\n\/\/ 157\r\nparseInt(0o34, 17)\t\/\/extracting base 17 equivalent of octal number\r\n\/\/ 42\r\nparseInt('ff', 8) \/\/out of the range of octal number\r\n\/\/ NaN<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-parseInt.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"img-gray-border aligncenter wp-image-66184 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-parseInt.jpg\" alt=\"JavaScript parseInt()\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-parseInt.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-parseInt-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-parseInt-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-parseInt-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-parseInt-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-parseInt-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p>Notice that we extracted the hex and octal methods with different specifications. We ignored <strong>0x<\/strong> with <strong>9d<\/strong>, but still got the expected result. When we tried to do the same with<strong> base 8<\/strong>, we got NaN. This is because numbers with <strong>base 8<\/strong> don\u2019t recognize the string as a <strong>hex<\/strong> number. You need to use <strong>0xff<\/strong> in its place if you want to find its value.<\/p>\n<h3>Adding Strings and Numbers<\/h3>\n<p>JavaScript <strong>+ operator<\/strong> works as both an arithmetic and string (concatenation) operator. When we add two or more numbers, we get the sum. But the moment a string enters the equation, concatenation operator comes into play. After the script encounters a string, it uses concatenation operator even for numbers. This is clear from the last statement in the program below. We expected <strong>1 + 2 + \u201c4\u201d + 2 + 1<\/strong> to produce the result <strong>343<\/strong> but got <strong>3421<\/strong>.<\/p>\n<p><em><strong>Don&#8217;t forget to explore our tutorial on <a href=\"https:\/\/data-flair.training\/blogs\/javascript-strings\/\">JavaScript Strings<\/a><\/strong><\/em><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">1 + 2 \/\/arithmetic operator    \/\/ 3\r\n\/\/concatenation operator\r\n\"4\" + 1 \/\/ 41\r\n1 + '2' \/\/ 12\r\n\/\/combining arithmetic and concatenation operators\r\n1 + 2 + \"4\" + 2 + 1 \/\/ 3421<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-number-strings.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"img-gray-border aligncenter wp-image-66185 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-number-strings.jpg\" alt=\"JavaScript number strings\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-number-strings.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-number-strings-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-number-strings-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-number-strings-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-number-strings-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-number-strings-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<h3>Imprecise Calculations<\/h3>\n<p><strong>Problem1:<\/strong><\/p>\n<p>Since the number is represented in <strong>64-bit format<\/strong>, internally, there are exactly 64 bits available to store a number. If a number exceeds this storage limit, we get an Infinity. This will cause errors and crash our application.<\/p>\n<p><strong>Problem2:<\/strong><\/p>\n<p>Another problem we might face while dealing with numbers is the loss of precision. It isn\u2019t always obvious but happens quite a lot.<\/p>\n<p>Let\u2019s first understand what I mean with the two problems above by testing the following code in the browser console.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">4e786 \/\/problem1\r\n\/\/ Infinity\r\n1.6 + 0.8\t\/\/problem2\r\n\/\/ 2.4000000000000004\r\n1.6 + 0.8 = 2.4 \/\/false<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-Imprise-Calculation.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"img-gray-border aligncenter wp-image-66186 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-Imprise-Calculation.jpg\" alt=\"JavaScript Imprise Calculation\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-Imprise-Calculation.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-Imprise-Calculation-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-Imprise-Calculation-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-Imprise-Calculation-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-Imprise-Calculation-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-Imprise-Calculation-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p>Okay, that wasn\u2019t what we expected, was it? We expected the result of <strong>1.6 + 0.8<\/strong> to be<strong> 2.4<\/strong>. And though close, it isn\u2019t the same; this will cause havoc in our programs. This is the reason we got <strong>false<\/strong> when compared with the expected result.<\/p>\n<p>Now you might be wondering why this happened and how to resolve it. We got an imprecise result of our calculations because fractions like <strong>1.6<\/strong> and <strong>1.8<\/strong> are unending in their binary form. Think of the value of <strong>pi (22\/7)<\/strong>: it goes on forever. But we use <strong>3.14<\/strong> for its value by rounding it to two digits and the same is possible for JavaScript numbers.<\/p>\n<p>We use the JavaScript <strong>toFixed()<\/strong> method to solve the dilemma. The syntax of this method is as follows:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">number.toFixed( ?precisionValue)<\/pre>\n<p>The parameter of this method specifies the precision i.e. number of figures on the right of the decimal. This method always returns a string, so to get a number, we can use a unary plus\u00a0at the beginning.<\/p>\n<p><em><strong>Learn to implement\u00a0the unary plus and several other <a href=\"https:\/\/data-flair.training\/blogs\/javascript-operator\/\">JavaScript Operators<\/a><\/strong><\/em><\/p>\n<p>Test the following code in the console:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">var pi = 22\/7\r\npi.toFixed(10) \/\/ \"3.1428571429\"\r\nvar sum = 1.6 + 0.8\r\nsum.toFixed(2) \/\/ \"2.40\"\r\n+sum.toFixed(2) \/\/ 2.4<\/pre>\n<p><strong>Output:<\/strong><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-tofixed.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"img-gray-border aligncenter wp-image-66187 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-tofixed.jpg\" alt=\"JavaScript tofixed()\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-tofixed.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-tofixed-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-tofixed-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-tofixed-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-tofixed-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-tofixed-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<h3>isNaN() and isFinite() methods<\/h3>\n<p><strong>NaN (Not-a-Number)<\/strong> is a keyword (reserved word) in JavaScript implying that the value is not a legal number. If you try to perform numeric calculations on non-numeric data values, the script returns <strong>NaN<\/strong>. However, in terms of strings with a numerical data value, we don\u2019t get a NaN due to type-casting. The <strong>typeof operator<\/strong> tells us that the NaN is a numeric data type.<\/p>\n<p>We can check if the value we get is a JavaScript number or not with the help of <strong>the isNan() method<\/strong>. It returns a Boolean value, depending on whether the value is a number <strong>(false)<\/strong> or not <strong>(true)<\/strong>. The code below implements the concept of NaN in the console.<\/p>\n<p><em>Note: <strong>NaN === NaN<\/strong> returns<strong> false<\/strong> because the value of <strong>NaN<\/strong> is not equal to anything, including itself.<\/em><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">num1 = 120 \/ \"DataFlair\" \/\/ NaN\r\nnum2 = 120 \/ \"10\"\t\/\/type-casting\r\n\/\/ 12\r\nisNaN(num1) \/\/ true\r\nisNaN(num2) \/\/ false\r\nisNaN() \/\/ true\r\ntypeof NaN \/\/ \"number\"<\/pre>\n<p><b>Output:<\/b><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-Numbers-isNaN.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"img-gray-border aligncenter wp-image-66192 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-Numbers-isNaN.jpg\" alt=\"JavaScript Numbers isNaN()\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-Numbers-isNaN.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-Numbers-isNaN-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-Numbers-isNaN-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-Numbers-isNaN-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-Numbers-isNaN-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-Numbers-isNaN-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p>In the topic above, we encountered <strong>Infinity<\/strong> for larger numbers. We don\u2019t want our program to return this value until we specifically mention it. The script returns <strong>Infinity<\/strong> (or <strong>-Infinity<\/strong>) when you try to calculate a number outside the range of JavaScript numbers. The <strong>typeof<\/strong> <strong>operator<\/strong> returns <strong>\u2018number\u2019 for Infinity.<\/strong><\/p>\n<p>Using the <strong>isFinite()<\/strong> method, we can check if a number is a regular number (returns true) or <strong>NaN, Infinity or -Infinity<\/strong> (returns <strong>false<\/strong>).<\/p>\n<p>Try the following code in your console window to verify what we\u2019ve discussed about Infinity.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">typeof Infinity \/\/ \"number\"\r\nisFinite(NaN) \/\/ false\r\nisFinite(\"DataFlair\") \/\/ false\r\nisFinite(14) \/\/ true\r\nisFinite(Infinity) \/\/ false\r\nisFinite() \/\/ false\r\n<\/pre>\n<p><b>Output:<\/b><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-Number-infinity.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"img-gray-border aligncenter wp-image-66193 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-Number-infinity.jpg\" alt=\"JavaScript Number infinity\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-Number-infinity.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-Number-infinity-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-Number-infinity-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-Number-infinity-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-Number-infinity-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-Number-infinity-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><em><strong>Hold On! Did you check the article on\u00a0<a href=\"https:\/\/data-flair.training\/blogs\/javascript-objects\/\">JavaScript Objects<\/a>?<\/strong><\/em><\/p>\n<h3>The Number Object<\/h3>\n<p>The<strong> Number<\/strong> object is a wrapper object that works with numerical data values. Until now, we worked with numeral literals<strong> (var number = value<\/strong>), but we can create a <strong>Number object<\/strong> with the <strong>Number() constructor<\/strong>. The syntax of creating a Number object is as follows:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">var num = new Number(value);\r\n<\/pre>\n<h3>Properties of Number Object<\/h3>\n<p>The following are the properties associated with a Number object:<\/p>\n<table dir=\"ltr\">\n<colgroup>\n<col width=\"100\" \/>\n<col width=\"100\" \/><\/colgroup>\n<tbody>\n<tr>\n<td style=\"text-align: center\"><strong>Property<\/strong><\/td>\n<td style=\"text-align: center\"><strong>Description<\/strong><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\">MAX_VALUE<\/td>\n<td>\n<div>\n<div style=\"text-align: center\">It is the largest positive representable number.<\/div>\n<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\">MAX_SAFE_INTEGER<\/td>\n<td>\n<div>\n<div style=\"text-align: center\">It represents the largest safe integer number (253 &#8211; 1).<\/div>\n<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\">MIN_VALUE<\/td>\n<td>\n<div>\n<div style=\"text-align: center\">It is the smallest positive representable number i.e. the number closest to zero without actually being zero.<\/div>\n<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\">MIN_SAFE_INTEGER<\/td>\n<td>\n<div>\n<div style=\"text-align: center\">It represents the smallest safe integer number (-(253 &#8211; 1)).<\/div>\n<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\">NaN<\/td>\n<td>\n<div>\n<div style=\"text-align: center\">It equals to a special value that is \u201cnot a number\u201d.<\/div>\n<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\">POSITIVE_INFINITY<\/td>\n<td>\n<div>\n<div style=\"text-align: center\">It is a special value representing infinity, returned on overflow.<\/div>\n<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\">NEGATIVE_INFINITY<\/td>\n<td>\n<div>\n<div style=\"text-align: center\">It is a special value representing negative infinity, returned on overflow.<\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>The program below implements the different Number properties that we discussed.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">Number.MAX_VALUE \/\/ 1.7976931348623157e+308\r\nNumber.MAX_SAFE_INTEGER \/\/ 9007199254740991\r\nNumber.MIN_VALUE \/\/ 5e-324\r\nNumber.MIN_SAFE_INTEGER \/\/ -9007199254740991\r\nNumber.NaN \/\/ NaN\r\nNumber.POSITIVE_INFINITY \/\/ Infinity\r\nNumber.NEGATIVE_INFINITY \/\/ -Infinity<\/pre>\n<p><b>Output:<\/b><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-number-properties.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"img-gray-border aligncenter wp-image-66194 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-number-properties.jpg\" alt=\"JavaScript number properties\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-number-properties.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-number-properties-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-number-properties-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-number-properties-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-number-properties-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-number-properties-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<h3>JavaScript Number Methods<\/h3>\n<p>The table below lists all the methods you need to focus on.<\/p>\n<table dir=\"ltr\">\n<colgroup>\n<col width=\"191\" \/>\n<col width=\"191\" \/><\/colgroup>\n<tbody>\n<tr>\n<td style=\"text-align: center\"><strong>Method<\/strong><\/td>\n<td style=\"text-align: center\"><strong>Description<\/strong><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\">toExponential(?fractionDigits)<\/td>\n<td>\n<div>\n<div style=\"text-align: center\">It returns the exponential value as a string.<\/div>\n<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\">toPrecision(?precision)<\/td>\n<td>\n<div>\n<div style=\"text-align: center\">It returns the number as a string with <strong>precision<\/strong> digits in total.<\/div>\n<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\">toString(?radix)<\/td>\n<td>\n<div>\n<div style=\"text-align: center\">It returns the string representation of the object in the specified radix.<\/div>\n<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\">valueOf()<\/td>\n<td>\n<div>\n<div style=\"text-align: center\">It returns the primitive value of the specified object.<\/div>\n<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\">isInteger()<\/td>\n<td>\n<div>\n<div style=\"text-align: center\">It determines whether the value passed is an integer or not.<\/div>\n<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\">isSafeInteger()<\/td>\n<td>\n<div>\n<div style=\"text-align: center\">It determines whether the value passed is a safe integer or not.<\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Let\u2019s implement these methods in the console window.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">num = 250 \/\/ 250\r\nnum.toExponential() \/\/ \"2.5e+2\"\r\nnum.toExponential(2) \/\/ \"2.50e+2\"\r\nnum.toPrecision(5) \/\/ \"250.00\"\r\nnum.toString(17) \/\/ \"ec\"\r\nnum.valueOf() \/\/ 250<\/pre>\n<p><b>Output:<\/b><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-number-methods.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"img-gray-border aligncenter wp-image-66195 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-number-methods.jpg\" alt=\"JavaScript number methods\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-number-methods.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-number-methods-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-number-methods-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-number-methods-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-number-methods-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-number-methods-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<h3>Converting different Data Types to Numbers<\/h3>\n<p>The following code in your browser console window will convert different JavaScript values into a Number object.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">Number() \/\/ 0\r\nNumber(\"\") \/\/ 0\r\nNumber(\"12\") \/\/ 2\r\nNumber(\"12.50\") \/\/ 12.5\r\nNumber(\"125e-2\") \/\/ 1.25\r\nNumber(null) \/\/ 0\r\nNumber(\"null\") \/\/ NaN\r\nNumber(0xff) \/\/ 255\r\nNumber(0o150) \/\/ 104\r\nNumber(0b110) \/\/ 6\r\nvar date = new Date()\r\ndate \/\/ Fri Jul 26 2019 14:25:45 GMT+0530 (India Standard Time)\r\nNumber(date) \/\/ 1564131345705\r\n<\/pre>\n<p>We also used the <strong>Date<\/strong> object in the last three statements. We will discuss what they are and how they work in the next tutorial of this series.<\/p>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/converting-JavaScript-Number.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"img-gray-border aligncenter wp-image-66196 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/converting-JavaScript-Number.jpg\" alt=\"converting JavaScript Number\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/converting-JavaScript-Number.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/converting-JavaScript-Number-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/converting-JavaScript-Number-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/converting-JavaScript-Number-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/converting-JavaScript-Number-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/converting-JavaScript-Number-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<h2>Summary<\/h2>\n<p>Here we come to the end of our tutorial on JavaScript Numbers. In this article, we took a brief look at the concepts of numbers in JavaScript, various approaches to write a number in JavaScript and different terminologies attached to it. We also learned about JavaScript Number object.<\/p>\n<p><em><strong>Next, you must go through our <a href=\"https:\/\/data-flair.training\/blogs\/javascript-date-and-time\/\">tutorial on JavaScript Date and Time<\/a><\/strong><\/em><\/p>\n<p>Hope you liked our article. Don&#8217;t forget to share your views through the comment section below.<span hidden class=\"__iawmlf-post-loop-links\" data-iawmlf-links=\"[{&quot;id&quot;:1454,&quot;href&quot;:&quot;https:\\\/\\\/en.wikipedia.org\\\/wiki\\\/JavaScript&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20251208180004\\\/https:\\\/\\\/en.wikipedia.org\\\/wiki\\\/JavaScript&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2025-12-09 07:25:01&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-12 10:12:19&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-19 20:12:26&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-23 14:26:43&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-26 20:33:05&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-30 03:46:49&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-03 10:04:10&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-08 07:59:48&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-11 13:08:47&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-16 08:13:22&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-20 13:51:36&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-24 03:23:30&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-28 01:26:04&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-31 06:28:41&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-03 10:56:46&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-10 05:25:16&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-13 14:40:22&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-16 17:27:49&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-20 11:10:49&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-26 10:59:31&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-02 23:12:45&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-07 09:23:37&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-16 15:08:09&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-20 11:51:02&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-26 05:27:11&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-01 15:53:39&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-05 04:38:58&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-10 05:37:32&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-14 10:47:54&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-17 11:57:53&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-21 02:42:11&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-24 09:17:36&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-28 02:46:05&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-01 07:17:08&quot;,&quot;http_code&quot;:429},{&quot;date&quot;:&quot;2026-05-05 18:21:06&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-11 11:12:51&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-14 16:04:50&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-17 16:56:01&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-21 17:58:16&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-25 08:21:54&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-30 04:19:24&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-02 22:21:06&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-06-06 18:08:05&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-11 08:17:02&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-15 08:00:22&quot;,&quot;http_code&quot;:200}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-06-15 08:00:22&quot;,&quot;http_code&quot;:200},&quot;process&quot;:&quot;done&quot;}]\"><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>We use numbers to count, measure and label. We\u2019ve been learning about them since playschool and we still use them as adults. We deal with numbers in our everyday life, may it be our&#46;&#46;&#46;<\/p>\n","protected":false},"author":7,"featured_media":66198,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18979],"tags":[20792,20791,20722,20790],"class_list":["post-65388","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript","tag-isnan-and-isfinite-methods","tag-javascript-number-methods","tag-javascript-numbers","tag-number-object-properties"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>JavaScript Numbers - Get Skilled in the implementation of its Methods! - DataFlair<\/title>\n<meta name=\"description\" content=\"Learn the concept of JavaScript Numbers &amp; understand the different methods to write a number in JavaScript. Also, explore the process to add strings &amp; numbers and properties of Number object.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/javascript-numbers\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JavaScript Numbers - Get Skilled in the implementation of its Methods! - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Learn the concept of JavaScript Numbers &amp; understand the different methods to write a number in JavaScript. Also, explore the process to add strings &amp; numbers and properties of Number object.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/javascript-numbers\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2019-08-02T12:36:16+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-02-17T16:02:26+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-Numbers.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"802\" \/>\n\t<meta property=\"og:image:height\" content=\"420\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"JavaScript Numbers - Get Skilled in the implementation of its Methods! - DataFlair","description":"Learn the concept of JavaScript Numbers & understand the different methods to write a number in JavaScript. Also, explore the process to add strings & numbers and properties of Number object.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/javascript-numbers\/","og_locale":"en_US","og_type":"article","og_title":"JavaScript Numbers - Get Skilled in the implementation of its Methods! - DataFlair","og_description":"Learn the concept of JavaScript Numbers & understand the different methods to write a number in JavaScript. Also, explore the process to add strings & numbers and properties of Number object.","og_url":"https:\/\/data-flair.training\/blogs\/javascript-numbers\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2019-08-02T12:36:16+00:00","article_modified_time":"2021-02-17T16:02:26+00:00","og_image":[{"width":802,"height":420,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-Numbers.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/javascript-numbers\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/javascript-numbers\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/beb0cab24b7aa54423a3b50e669a9dcd"},"headline":"JavaScript Numbers &#8211; Get Skilled in the implementation of its Methods!","datePublished":"2019-08-02T12:36:16+00:00","dateModified":"2021-02-17T16:02:26+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/javascript-numbers\/"},"wordCount":1704,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/javascript-numbers\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-Numbers.jpg","keywords":["isNaN() and isFinite() methods","JavaScript Number Methods","JavaScript Numbers","Number Object Properties"],"articleSection":["JavaScript Tutorial"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/javascript-numbers\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/javascript-numbers\/","url":"https:\/\/data-flair.training\/blogs\/javascript-numbers\/","name":"JavaScript Numbers - Get Skilled in the implementation of its Methods! - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/javascript-numbers\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/javascript-numbers\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-Numbers.jpg","datePublished":"2019-08-02T12:36:16+00:00","dateModified":"2021-02-17T16:02:26+00:00","description":"Learn the concept of JavaScript Numbers & understand the different methods to write a number in JavaScript. Also, explore the process to add strings & numbers and properties of Number object.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/javascript-numbers\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/javascript-numbers\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/javascript-numbers\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-Numbers.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/JavaScript-Numbers.jpg","width":802,"height":420,"caption":"JavaScript Numbers"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/javascript-numbers\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"JavaScript Tutorial","item":"https:\/\/data-flair.training\/blogs\/category\/javascript\/"},{"@type":"ListItem","position":3,"name":"JavaScript Numbers &#8211; Get Skilled in the implementation of its Methods!"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/beb0cab24b7aa54423a3b50e669a9dcd","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/c322416204232f4dd97ef3901b0a499a5d34d7ba7fe333f4bfe53a907873d293?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/c322416204232f4dd97ef3901b0a499a5d34d7ba7fe333f4bfe53a907873d293?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c322416204232f4dd97ef3901b0a499a5d34d7ba7fe333f4bfe53a907873d293?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team specializes in creating clear, actionable content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Backed by industry expertise, we make learning easy and career-oriented for beginners and pros alike.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam3\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/65388","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=65388"}],"version-history":[{"count":14,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/65388\/revisions"}],"predecessor-version":[{"id":67679,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/65388\/revisions\/67679"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/66198"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=65388"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=65388"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=65388"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}