DEV Community

gorgin-dev
gorgin-dev

Posted on

1

two tiny features about numbers in javascript that many of js developer don't know!

hello everyone
this post is about my last post about javascript features in my youtube channel and this this post i'll tell you about number separator in js and also fastest possible way to convert string to number!

Number Separator

when you work large numbers it's hard to read them by eyes so you can use underscore to separate digits in number for example :
let a = 10_000_000 //is equivalent to let a = 10000000 but more readable!

Fastest possible way to convert string to number

as for sure all of you know there are many different ways to convert string to number for example
if we have variable b and c :

let b = '500'
let c

then variable b can convert to number in fallowing ways:
c = Number(b)
//or
c = b - 0
//or
c = parsInt(b)

but the fastest possible way is add + right before string like this:
c = +b

then b converted to number and then assigns to b

hope you enjoy!

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay