Swapna Kumar Panda โœจ Profile picture
Jan 18 โ€ข 6 tweets โ€ข 2 min read
How is "Divide by Zero" handled in JavaScript?

๐Ÿงต
โžŠ Why is "Divide by Zero" special?

Let's say

a รท 0 = y
โ‡’ a = y ร— 0
โ‡’ a = 0

It means

โฌ” a non-zero number can never be divided by zero

โฌ• as any number multiplied by zero is zero, 0 รท 0 is also indeterminate
โž‹ How do programming languages handle it?

โ‘ As we saw above, division by zero in every scenario is indeterminate.

โ’ Many programming languages consider it a special case and throws error/exception at runtime.

โ‘ To handle, we need to catch the error.
โžŒ "Divide by Zero" in JavaScript

โ‘ JavaScript is unique in the league and handles it differently

โ’ JavaScript doesn't throw any error. Then?

โฌ– 0 / 0 โ‡’ NaN
โฌ˜ Positive Number / 0 โ‡’ Infinity
โฌ— Negative Number / 0 โ‡’ -Infinity
โž Why does JavaScript handle this way?

โ‘ One reason could be because JavaScript is dynamic typed.

โ’ "/" operation coerces non-numbers to numbers.

โ‘ Throwing some exception at runtime would have been inconvenient.

Do you see any other reason? Reply ๐Ÿ’ฌ
With this we come to the end of this ๐Ÿงต where we discussed about "Divide by Zero operation in JavaScript".

If you don't want to miss such tutorial threads on HTML, CSS and, JavaScript, follow {@swapnakpanda}

Till we meet again, stay safe and stay sanitised. ๐Ÿ‘‹

โ€ข โ€ข โ€ข

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

Jan 19
๐Ÿ’ซ 100 Inspiring Accounts

If their tweets appeared in your timeline, you would definitely learn something new.

They are experts in

๐Ÿ™ Web Development
๐ŸŽ‘ UI/UX
๐Ÿ‘ฉโ€๐Ÿ’ป Programming
๐Ÿ›ข Database
๐Ÿ›  System Design
๐Ÿ”ฉ Machine Learning
๐ŸŽฏ DSA
โ›“ Blockchain
๐ŸŒ Web3
Read 8 tweets
Jan 16
What is < onclick=" return false;" > in HTML?

โ‡ฉ
โžŠ Why is it used?

โ‘ Events automatically lead to certain actions performed by the browser.

โ’ In some cases, we may not want default action to be performed.

โ‘ "return false" triggers browser to prevent taking default action.
โž‹ Let's break it down

โœ› onclick
It's an HTML attribute.
It's being used to set inline event handlers.

โœ› =""
The code written inside "" should be valid JS code.

โœ› return false
Returning false from an inline event handler
Read 8 tweets
Jan 16
๐Ÿ’™ 10K+ Followers
๐Ÿ“… 15-JAN

1K โ‡จ First 3 months
10K โ‡จ Next 3 months

Though I have been sharing the best possible learning contents, the kind of love and support I have received from you all is beyond my words.

You will receive even better contents, that's my promise

โ†“
To never pollute my timeline, I rarely share any non-educational tweets.

Today I thought of sharing few single-liners that I wrote before but never able to post them.

Please read and share your views.
Just because a 12 yo doing Web Dev, don't mistaken it as a child's stuff.
Read 10 tweets
Jan 14
What is <a href="javascript:void(0)" > in HTML?

โ‡ฉ
โžŠ Why is it used?

โ‘ When we click on a link, if we do not want the default behaviour of the browser to load a new page or refresh the same page.

โ’ Instead, the browser performs the JavaScript attached to that link.
โž‹ Let's break it down

โœ› javascript:
This is referred to as a Pseudo URL

โœ› void
This is a JavaScript Operator

โœ› (0)
This is a JavaScript Expression
Read 12 tweets
Jan 10
While "2" - 2 = 0, why is "2" + 2 = "22"?

A JavaScript ๐Ÿงต
โžŠ '+' operator is overloaded for Strings

โ‘ The binary '+' operator is generally a "Number Addition" operator.

โ’ When one of the operand is string, '+' rather acts like a "String Concatenation" operator. The other operand if not string is converted to string first.
โž‹ '-' operator operates on numbers only

โ‘ The binary "-" operator is known as a "Number Subtraction" operator.

โ’ If any of the operand is not number, that is first converted to a number before evaluating the expression.
Read 8 tweets
Jan 4
Why <!DOCTYPE html>?

โ‡ฉ
โžŠ History

โœช In the old days of the web, pages were written in two versions: One for Netscape Navigator, and one for Microsoft IE.

โœช When the web standards were made at W3C, browsers could not just start using them, as doing so would break most existing sites on the web.
โœช Browsers therefore introduced two modes to treat new standards compliant sites differently from old legacy sites.

โœช Modes are: Quirks Mode and Standards Mode.

โœช For HTML documents, browsers use a DOCTYPE in the beginning of the document to decide which mode to handle.
Read 9 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!

:(