{"id":28811,"date":"2022-05-04T11:30:39","date_gmt":"2022-05-04T06:00:39","guid":{"rendered":"https:\/\/tutorial.eyehunts.com\/?p=28811"},"modified":"2023-09-05T17:43:25","modified_gmt":"2023-09-05T12:13:25","slug":"how-to-avoid-nan-in-javascript-basic-code","status":"publish","type":"post","link":"https:\/\/tutorial.eyehunts.com\/js\/how-to-avoid-nan-in-javascript-basic-code\/","title":{"rendered":"How to avoid NaN in JavaScript | Basic code"},"content":{"rendered":"\n<p>JavaScript NaN is the return value from operations that have an undefined numerical result. NaN is an error value that means <a href=\"https:\/\/tutorial.eyehunts.com\/js\/isnan-javascript-function-check-value-is-nannot-a-number\/\">not a number<\/a>. Below are 4 methods with examples to avoid NaN in JavaScript.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Avoid NaN in JavaScript<\/h2>\n\n\n\n<p>Simple example code.<\/p>\n\n\n\n<p><strong>1. Mathematical operations with non-numeric string values<\/strong><\/p>\n\n\n\n<p>Sometimes stringed values may come back from an API, just check if the value is <code>NaN<\/code> in the first place.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const y = 5 * \"Apples\"; \/\/ NaN\n\nisNaN(\"5\") || 0\n<\/code><\/pre>\n\n\n\n<p>To avoid it completely, it\u2019s best if you do all your mathematical operations with numbers.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p><strong>2. Mathematical operations with functions<\/strong><\/p>\n\n\n\n<p>Doing mathematical operations with a function will result in a <code>NaN<\/code> value.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function fooBar() {\n  \/\/ ...stuff\n}\nfooBar * 5 \/\/ NaN<\/code><\/pre>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p><strong>3. Mathematical operations with objects<\/strong><\/p>\n\n\n\n<p>Doing mathematical operations with a JavaScript object will result in a <code>NaN<\/code> value.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\nconst obj = {};\n\nobj * 5 \/\/ NaN\n<\/code><\/pre>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p><strong>4. Mathematical operations with falsy values<\/strong><\/p>\n\n\n\n<p>Avoid doing mathematical operations with falsy values such as:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code><a href=\"https:\/\/tutorial.eyehunts.com\/js\/javascript-undefined-property-variable-value\/\">undefined<\/a><\/code><\/li>\n\n\n\n<li><code>NaN<\/code><\/li>\n\n\n\n<li><code><a href=\"https:\/\/tutorial.eyehunts.com\/js\/what-is-null-in-javascript-basics\/\">null<\/a><\/code><\/li>\n\n\n\n<li><code>false<\/code><\/li>\n\n\n\n<li>empty string (<code>\"\"<\/code>)<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n&lt;body&gt;\n\n  &lt;script&gt;\n\n    const a = undefined + 5; \/\/ NaN\n\n    const b = NaN \/ 5; \/\/ NaN\n\n    const c = null - 5; \/\/ -5. Null behaves like a 0.\n\n    const d = false * 5; \/\/ -5. False behaves like a 0.\n\n    const e = \"\" + 10; \/\/ 10. Empty string behaves like a 0.\n\n    console.log(a,b,c,d,e)\n\n  &lt;\/script&gt;\n\n&lt;\/body&gt;\n&lt;\/html&gt; <\/code><\/pre>\n\n\n\n<p><strong>Output<\/strong>:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"232\" height=\"116\" src=\"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2022\/05\/How-to-avoid-NaN-in-JavaScript.jpg?resize=232%2C116&#038;ssl=1\" alt=\"How to avoid NaN in JavaScript\" class=\"wp-image-28958\"\/><\/figure><\/div>\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Return Zero if the input value is NaN<\/h3>\n\n\n\n<p>The shortest way:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var number = (yourVariable || 0)<\/code><\/pre>\n\n\n\n<p>Because <code>NaN<\/code> is a falsey value, this will return 0 whenever <code>yourVariable<\/code> is NaN.<\/p>\n\n\n\n<p>A way to check, if a number is NaN or not is to use the <a href=\"https:\/\/tutorial.eyehunts.com\/js\/isnan-javascript-function-check-value-is-nannot-a-number\/\"><code>isNaN<\/code> function<\/a>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>isNaN(yourVariable); \/\/ Returns true is yourVariable is NaN<\/code><\/pre>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>How do I prevent my output from being Nan?<\/strong><\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Just set a variable to <a href=\"https:\/\/tutorial.eyehunts.com\/js\/javascript-parseint-function-convert-a-string-to-an-integer-example\/\">parseInt(&#8230;)<\/a> and check to make sure that it is a number using <code>if(!isNaN(val)<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>let val = parseInt(Value);\n    if (!isNaN(val))\n      \/\/CODE\n  }<\/code><\/pre>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Comment if you have any doubts or suggestions on this JS NaN topic.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><strong>Note:<\/strong>&nbsp;The<strong>&nbsp;All JS Examples codes&nbsp;<\/strong>are&nbsp;tested on the Firefox browser and the Chrome browser.<\/p><p>OS:&nbsp;<strong>Windows 10<\/strong><\/p><p>Code: HTML 5 Version<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>JavaScript NaN is the return value from operations that have an undefined numerical result. NaN is an error value that means not a number. Below are 4 methods with examples to avoid NaN in JavaScript. Avoid NaN in JavaScript Simple example code. 1. Mathematical operations with non-numeric string values Sometimes stringed values may come back&hellip;&nbsp;<a href=\"https:\/\/tutorial.eyehunts.com\/js\/how-to-avoid-nan-in-javascript-basic-code\/\" rel=\"bookmark\">Read More &raquo;<span class=\"screen-reader-text\">How to avoid NaN in JavaScript | Basic code<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[69],"tags":[72,388],"post_series":[],"class_list":["post-28811","post","type-post","status-publish","format-standard","hentry","category-js","tag-js-basic","tag-js-nan"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.1.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to avoid NaN in JavaScript | Basic code<\/title>\n<meta name=\"description\" content=\"NaN is an error value that means not a number. Below are 4 methods with examples to avoid NaN in JavaScript.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/tutorial.eyehunts.com\/js\/how-to-avoid-nan-in-javascript-basic-code\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to avoid NaN in JavaScript | Basic code\" \/>\n<meta property=\"og:description\" content=\"NaN is an error value that means not a number. Below are 4 methods with examples to avoid NaN in JavaScript.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/tutorial.eyehunts.com\/js\/how-to-avoid-nan-in-javascript-basic-code\/\" \/>\n<meta property=\"og:site_name\" content=\"Tutorial\" \/>\n<meta property=\"article:published_time\" content=\"2022-05-04T06:00:39+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-09-05T12:13:25+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/tutorial.eyehunts.com\/wp-content\/uploads\/2022\/05\/How-to-avoid-NaN-in-JavaScript.jpg\" \/>\n<meta name=\"author\" content=\"Rohit\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Rohit\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/js\/how-to-avoid-nan-in-javascript-basic-code\/\",\"url\":\"https:\/\/tutorial.eyehunts.com\/js\/how-to-avoid-nan-in-javascript-basic-code\/\",\"name\":\"How to avoid NaN in JavaScript | Basic code\",\"isPartOf\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/js\/how-to-avoid-nan-in-javascript-basic-code\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/js\/how-to-avoid-nan-in-javascript-basic-code\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/tutorial.eyehunts.com\/wp-content\/uploads\/2022\/05\/How-to-avoid-NaN-in-JavaScript.jpg\",\"datePublished\":\"2022-05-04T06:00:39+00:00\",\"dateModified\":\"2023-09-05T12:13:25+00:00\",\"author\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1\"},\"description\":\"NaN is an error value that means not a number. Below are 4 methods with examples to avoid NaN in JavaScript.\",\"breadcrumb\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/js\/how-to-avoid-nan-in-javascript-basic-code\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/tutorial.eyehunts.com\/js\/how-to-avoid-nan-in-javascript-basic-code\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/js\/how-to-avoid-nan-in-javascript-basic-code\/#primaryimage\",\"url\":\"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2022\/05\/How-to-avoid-NaN-in-JavaScript.jpg?fit=232%2C116&ssl=1\",\"contentUrl\":\"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2022\/05\/How-to-avoid-NaN-in-JavaScript.jpg?fit=232%2C116&ssl=1\",\"width\":232,\"height\":116},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/js\/how-to-avoid-nan-in-javascript-basic-code\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/tutorial.eyehunts.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to avoid NaN in JavaScript | Basic code\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/#website\",\"url\":\"https:\/\/tutorial.eyehunts.com\/\",\"name\":\"Tutorial\",\"description\":\"By EyeHunts\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/tutorial.eyehunts.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1\",\"name\":\"Rohit\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777979855\",\"contentUrl\":\"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777979855\",\"caption\":\"Rohit\"},\"description\":\"Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology &amp; like learning technical.\",\"url\":\"https:\/\/tutorial.eyehunts.com\/author\/rohit\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to avoid NaN in JavaScript | Basic code","description":"NaN is an error value that means not a number. Below are 4 methods with examples to avoid NaN in JavaScript.","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:\/\/tutorial.eyehunts.com\/js\/how-to-avoid-nan-in-javascript-basic-code\/","og_locale":"en_US","og_type":"article","og_title":"How to avoid NaN in JavaScript | Basic code","og_description":"NaN is an error value that means not a number. Below are 4 methods with examples to avoid NaN in JavaScript.","og_url":"https:\/\/tutorial.eyehunts.com\/js\/how-to-avoid-nan-in-javascript-basic-code\/","og_site_name":"Tutorial","article_published_time":"2022-05-04T06:00:39+00:00","article_modified_time":"2023-09-05T12:13:25+00:00","og_image":[{"url":"https:\/\/tutorial.eyehunts.com\/wp-content\/uploads\/2022\/05\/How-to-avoid-NaN-in-JavaScript.jpg","type":"","width":"","height":""}],"author":"Rohit","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Rohit","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/tutorial.eyehunts.com\/js\/how-to-avoid-nan-in-javascript-basic-code\/","url":"https:\/\/tutorial.eyehunts.com\/js\/how-to-avoid-nan-in-javascript-basic-code\/","name":"How to avoid NaN in JavaScript | Basic code","isPartOf":{"@id":"https:\/\/tutorial.eyehunts.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/tutorial.eyehunts.com\/js\/how-to-avoid-nan-in-javascript-basic-code\/#primaryimage"},"image":{"@id":"https:\/\/tutorial.eyehunts.com\/js\/how-to-avoid-nan-in-javascript-basic-code\/#primaryimage"},"thumbnailUrl":"https:\/\/tutorial.eyehunts.com\/wp-content\/uploads\/2022\/05\/How-to-avoid-NaN-in-JavaScript.jpg","datePublished":"2022-05-04T06:00:39+00:00","dateModified":"2023-09-05T12:13:25+00:00","author":{"@id":"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1"},"description":"NaN is an error value that means not a number. Below are 4 methods with examples to avoid NaN in JavaScript.","breadcrumb":{"@id":"https:\/\/tutorial.eyehunts.com\/js\/how-to-avoid-nan-in-javascript-basic-code\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/tutorial.eyehunts.com\/js\/how-to-avoid-nan-in-javascript-basic-code\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/tutorial.eyehunts.com\/js\/how-to-avoid-nan-in-javascript-basic-code\/#primaryimage","url":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2022\/05\/How-to-avoid-NaN-in-JavaScript.jpg?fit=232%2C116&ssl=1","contentUrl":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2022\/05\/How-to-avoid-NaN-in-JavaScript.jpg?fit=232%2C116&ssl=1","width":232,"height":116},{"@type":"BreadcrumbList","@id":"https:\/\/tutorial.eyehunts.com\/js\/how-to-avoid-nan-in-javascript-basic-code\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/tutorial.eyehunts.com\/"},{"@type":"ListItem","position":2,"name":"How to avoid NaN in JavaScript | Basic code"}]},{"@type":"WebSite","@id":"https:\/\/tutorial.eyehunts.com\/#website","url":"https:\/\/tutorial.eyehunts.com\/","name":"Tutorial","description":"By EyeHunts","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/tutorial.eyehunts.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1","name":"Rohit","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/image\/","url":"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777979855","contentUrl":"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777979855","caption":"Rohit"},"description":"Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology &amp; like learning technical.","url":"https:\/\/tutorial.eyehunts.com\/author\/rohit\/"}]}},"jetpack_featured_media_url":"","jetpack-related-posts":[{"id":25005,"url":"https:\/\/tutorial.eyehunts.com\/js\/javascript-nan-property-not-a-number\/","url_meta":{"origin":28811,"position":0},"title":"JavaScript NaN property | Not-A-Number","author":"Rohit","date":"April 27, 2022","format":false,"excerpt":"JavaScript NaN's full form is \"Not-a-Number\". The global NaN property is a value representing Not-A-Number. The NaN property is a global property that represents the value NaN. Number.NaN NaN is a property of the global object. In other words, it is a variable in the global scope. Here are some\u2026","rel":"","context":"In &quot;JavaScript&quot;","block_context":{"text":"JavaScript","link":"https:\/\/tutorial.eyehunts.com\/category\/js\/"},"img":{"alt_text":"JavaScript NaN property","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2022\/04\/JavaScript-NaN-property.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":9144,"url":"https:\/\/tutorial.eyehunts.com\/js\/convert-nan-to-0-in-javascript-using-isnan-method-way\/","url_meta":{"origin":28811,"position":1},"title":"Convert NaN to 0 in JavaScript | Using isNan() method OR other method","author":"Rohit","date":"July 7, 2020","format":false,"excerpt":"Use isNan() method to Convert NaN to 0 in javascript. This method checks the given number is NaN or not. NaN means in JavaScript is \"Not a Number\". When you can expect the NaN Error in JS? One of the common situations when you try to convert string number to\u2026","rel":"","context":"In &quot;JavaScript&quot;","block_context":{"text":"JavaScript","link":"https:\/\/tutorial.eyehunts.com\/category\/js\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2020\/07\/Convert-NaN-to-0-in-JavaScript.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":9149,"url":"https:\/\/tutorial.eyehunts.com\/js\/isnan-javascript-function-check-value-is-nannot-a-number\/","url_meta":{"origin":28811,"position":2},"title":"isNaN JavaScript function | Check value is NaN(Not a Number)","author":"Rohit","date":"July 8, 2020","format":false,"excerpt":"The isNaN()\u00a0Function used to determine whether the passed value is NaN(Not a Number)\/illegal number in JavaScript. The global isNaN() function, converts the tested (given) value to a Number, then tests it. Syntax isNaN(value) Parameter Values The value which is to be tested for NaN. Return Value This function returns true\u2026","rel":"","context":"In &quot;JavaScript&quot;","block_context":{"text":"JavaScript","link":"https:\/\/tutorial.eyehunts.com\/category\/js\/"},"img":{"alt_text":"Examples of isNaN JavaScript function","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/\/wp-content\/uploads\/2020\/07\/isNaN-JavaScript-function-300x84.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":28800,"url":"https:\/\/tutorial.eyehunts.com\/js\/how-to-convert-nan-to-number-in-javascript-example-code\/","url_meta":{"origin":28811,"position":3},"title":"How to convert NaN to number in JavaScript | Example code","author":"Rohit","date":"April 27, 2022","format":false,"excerpt":"You can convert NaN to a number by using the direct JavaScript method. But using the isNaN() method can check whether the given number is NaN or not. if isNaN() returns true(means its not a number) you can assign whatever number you need to that variable <script> number = NaN;\u2026","rel":"","context":"In &quot;JavaScript&quot;","block_context":{"text":"JavaScript","link":"https:\/\/tutorial.eyehunts.com\/category\/js\/"},"img":{"alt_text":"How to convert NaN to number in JavaScript","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2022\/04\/How-to-convert-NaN-to-number-in-JavaScript.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":6586,"url":"https:\/\/tutorial.eyehunts.com\/js\/convert-javascript-string-to-int-javascript-parseint-function\/","url_meta":{"origin":28811,"position":4},"title":"Convert Javascript string to int | javascript parseint() function","author":"Rohit","date":"July 22, 2019","format":false,"excerpt":"You can convert string to int in Javascript using a parseint() function, but before the start, you must new about how javascript represent strings and integer. The\u00a0parseInt()\u00a0is an inbuilt function in JavaScript used to convert a string into an integer. Below code of basic int and strings declaration in JS:-\u2026","rel":"","context":"In &quot;JavaScript&quot;","block_context":{"text":"JavaScript","link":"https:\/\/tutorial.eyehunts.com\/category\/js\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2019\/07\/Convert-Javascript-string-to-int-parseint-function-1.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2019\/07\/Convert-Javascript-string-to-int-parseint-function-1.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2019\/07\/Convert-Javascript-string-to-int-parseint-function-1.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2019\/07\/Convert-Javascript-string-to-int-parseint-function-1.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":28649,"url":"https:\/\/tutorial.eyehunts.com\/js\/javascript-number-method-converts-a-value-to-a-number\/","url_meta":{"origin":28811,"position":5},"title":"JavaScript Number() method | Converts a value to a number","author":"Rohit","date":"April 26, 2022","format":false,"excerpt":"Use JavaScript Number() method to convert a string or other value to the Number type. If the value cannot be converted, NaN is returned. Number(value) Note: it will return values based on input. booleans, Number() returns 0 or 1. dates, Number() returns milliseconds since January 1, 1970 00:00:00. strings, Number()\u2026","rel":"","context":"In &quot;JavaScript&quot;","block_context":{"text":"JavaScript","link":"https:\/\/tutorial.eyehunts.com\/category\/js\/"},"img":{"alt_text":"JavaScript Number method","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2022\/04\/JavaScript-Number-method.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts\/28811","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/comments?post=28811"}],"version-history":[{"count":1,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts\/28811\/revisions"}],"predecessor-version":[{"id":41845,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts\/28811\/revisions\/41845"}],"wp:attachment":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/media?parent=28811"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/categories?post=28811"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/tags?post=28811"},{"taxonomy":"post_series","embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/post_series?post=28811"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}