💙 NaN in JavaScript

Operations evaluating to NaN
↳ Conversion to a Number
↳ Parsing to a Number
↳ Indeterminate Forms
↳ Math functions

Let's explore.

1️⃣ Conversion to a Number

Conversion happens in 2 ways in JavaScript

↳ Implicit Conversion
Operations where a number is expected
Example: Unary +, Binary - etc
↳ Explicit Conversion
Using Number() or, new Number()

Let's see what are evaluated to NaN Image
2️⃣ Parsing to a Number

There are 2 number parsing methods

↳ parseInt
↳ parseFloat

The process is,

✪ Leading and trailing spaces are ignored
✪ If the first character cannot be converted to a number, NaN is returned
✪ Only the first number found is returned
3️⃣ Indeterminate Forms

Some indeterminate forms which evaluate to NaN are,

⇰ 0 / 0
⇰ 0 % 0
⇰ 0 * Infinity
⇰ Infinity - Infinity
⇰ -Infinity + Infinity
⇰ Infinity / Infinity
⇰ Infinity % Infinity
⇰ Infinity % 0
4️⃣ Math functions

If invalid arguments are passed to Math functions, they may return NaN.

Example:

✪ Square root of a negative number
Math.pow(-2, 1/2)

✪ Logarithm of a negative number
Math.log2(-2)

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Swapna Kumar Panda ✨

Swapna Kumar Panda ✨ Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @swapnakpanda

4 Dec
💙 Are you new to DSA?

Attempt these 20 simple problems today to make your "logic building" strong.

1️⃣ Recursion

✪ Print a pattern (eg. triangle of numbers/asterisks)
✪ Sum of digits of a number
✪ Sum of natural numbers
✪ Factorial of a number
✪ Print Fibonacci Sequence
✪ Check if a string/number is palindrome
✪ Reverse a string/number/array
2️⃣ Divide and Conquer

✪ Find exponential of a number
✪ Search element in a sorted array/matrix
✪ Floor in a sorted array
✪ Merge 2 sorted arrays to create another sorted array
✪ Find median of 2 sorted arrays (same & different size)
✪ kth element in 2 sorted arrays
Read 4 tweets
3 Dec
💜 JavaScript Cheat Sheet

Converting any type of data to a Number, String and Boolean type.

Image
There are few entries in the above cheat sheet that are marked with "Red Lines". That has a purpose.

Many would guess the output incorrectly. So those are for your attention.
If you want to check the v1.0 of this cheat sheet (which was published in September), check 👇

Read 5 tweets
1 Dec
🙏 🙏 🙏 🙏 🙏

Thank you November. More contents coming in December which you wouldn't like to miss.

⇨ DSA
⇨ SQL / NoSQL
⇨ JavaScript
⇨ HTML / CSS
⇨ Python
⇨ System Design

I will share everything from my 15 years of experience. Want to know more about me?

Image
↱ ↰
TECH STACK
↳ ↲

⇰ 2001-2006
↳ C🔹C++🔸DSA🔹Oracle

⇰ 2006-2016
↳ Java🔹JavaScript🔸HTML/CSS
↳ REST🔹MQs

⇰ 2016-2021
↳ React🔹MongoDB🔸GraphQL
↳ Python🔸ML
↳ Git🔹Cloud Computing
↱ ↰
FUTURE LEARNING
↳ ↲

⇰ 2022-~
↳ Docker🔹Kubernetes🔸Microservices
↳ Web 3🔹Blockchain🔸Ethereum
↳ Solidity🔹Rust

+++
Read 4 tweets
29 Nov
💙 7 Types of Algorithms

↳ Brute Force
↳ Recursive
↳ Divide & Conquer
↳ Greedy
↳ Dynamic
↳ Backtracking
↳ Randomised

1️⃣ Brute Force Algorithm

✪ It is the most common type of algorithm. Every problem can be solved by brute force approach although generally not most effective.

✪ To design an optimal solution, we need to get a solution first at least and then it may be optimised.
2️⃣ Recursive Algorithm

✪ Recursion simply means calling itself to solve its subproblems.

Example: Factorial(n) = n * Factorial(n-1)
Read 10 tweets
28 Nov
~150 Days
>90 Threads
>50 Infographics

✪ DSA
✪ SQL / NoSQL
✪ JavaScript
✪ Python
✪ HTML / CSS
✪ System Design
✪ Cloud Computing

Concepts, Tips, Interview Questions and what not. This is what I am doing for you, all available in Public.

Links 👇. RETWEET for more reach.
Searching an old Tweet is tedious. I have made the job easier for you.

I have created numerous Moments for each Topic. All my tweets/threads can be accessed just like this 🤌

Find links 👇.

Share these with your friends. Let's spread the knowledge for FREE. 🤗🙌
💜 Interview Questions

twitter.com/i/events/14559…
Read 13 tweets
27 Nov
💡 Memorise Data Structures in 6 Steps 🚀

→ Array
↳ 1-Dimensional
↳ Multi Dimensional
→ Linked List
↳ Single
↳ Double
↳ Circular
→ Stack
→ Queue
→ Set
→ Hash Table
→ Tree
↳ Binary Tree
↳ Binary Search Tree
→ Graph

1️⃣ Type

↳ Linear
↳ Non-Linear
2️⃣ Memory Allocation

↳ Contiguous
↳ Non-contiguous
Read 7 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(