Elham Poshtiban 👩🏼‍💻’s Post

🤯 Mind Blown! How on earth did I not know this!!! DID YOU KNOW? In JavaScript, adding a unary plus (+) in front of a value is the quickest way to coerce it to a number. It's super handy for quick, clean conversions. This tiny operator saves you typing Number() and works on almost everything 💡 Quick Win with Inputs This trick shines when dealing with HTML inputs, which always return strings. Using the unary plus and the OR operator (||) guarantees you get a number or a safe default. Tiny operator, big convenience for keeping your types clean. What other hidden JavaScript gems should we uncover next? #JavaScript #React #WebDev #Frontend #SoftwareEngineer #FrontEndDeveloper #Tips #OpenToWork #jobSearch #Hiring

  • text

this is basically the "+string" conversion thing in javascript, if you try a string value instead of "e.target.value" you will get the same result.

This kind of works, but BigInts will throw a TypeError due to the loss of precision and it's not very legible/predictable

Rakshith Yadhav

I Help You Master System Design to Land Senior Roles & Ace Interviews | Senior Lead Engineer

7mo

Amazing insights! It's fun to find hidden code tricks Elham Poshtiban 👩🏼💻

See more comments

To view or add a comment, sign in

Explore content categories