Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
If I'm correct, parse functions don't do any math. So it stops at the +. The first two are words, so it comes back as NaN, and the last one is a 1.
At least that's my best guess.
If a language allowed you to parse "0/0" as an int it would make injections much easier. -
github95487y@AlgoRythm haha.. but I think all validations always works in server side nowadays and JS hacks won't pass through...
-
@AlgoRythm You are kinda correct. It simply extracts digits until it finds something that is not digit.
parseInt("test1") =>NaN
parseInt("1test") => 1
"1+infinity" => "1+infinity"
parseInt("1+4") => 1 -
github95487y@paziek yup.. I also assume it's the same logic.. but still it should return NaN since it's not a number
-
hawkes15687yThe unfounded JavaScript hate is real.
It's not like Integer.Parse("1+4") gives you 5 either.
If you try to use a saw to tighten a screw, don't blame the tool. -
@github unfortunately that isn't the case, The number of sites/apps which only do front-end validation for critical data is > 0
I know of a few, 1 is an ecommerce platform where you can even specify the price you want to pay through the frontend due to some senior retards being retarded and managment refusing to give the few non retards working there access to fix it because "noone else knows about it so its not a problem") -
@github It shouldn't, because parseInt is not made for casting, but for extracting and converting integer from provided value. It will return NaN only if value fails to meet requirements described in here: https://ecma-international.org/ecma...
or here: https://w3schools.com/jsref/... MDN: https://developer.mozilla.org/en-US...
You can't just assume what function does simply by looking at its name and taking wild guess. -
github95487y@hawkes 😂😂😂 the unfounded js hate..
This was just a joke..
I am an avid fan of js though.. currently planning to work on making a parser during coming weekends.. -
My advice is to cast all variables to what you expect them to be, then you won't have to worry about all those implicit behind-the-scenes things going on when using weak typed languages.
parseInt(Number("1")+Number("Infinity")) => NaN
because
Number("1")+Number("Infinity") => Infinity
1-"Infinity" => -Infinity
1+"Infinity" => "1Infinity"
1+Number("Infinity") => Infinity
You get numerical operator in first, because strings don't have "-" operator. You get string operator in second, because if there is string on either side of operator AND said operator is supported by string, then that will be always used. Third example has numeric values on both sides, so numeric operator is used. -
github95487y@paziek you took it too seriously dude.. thanks for sharing the links and your elaborated explanation..
I have worked in production codes in js with proper code reviews from senior devs too.. and knows good amount of stuffs in js when to do what..
I just posted it as joke.. and such snippets should never be used in actual codes.. -
So now we are reposting the reposts? even looks like taken from that exact repost gif... 😥
-
@github This exact same thing has been posted atleast 20 times, either reposted in worse quality to fool the system, taken straight from reddit, added some "😂😂😂😂😂" etc.
There has been discussions, rants about it being reposts, philosophers trying to tryhard intepret "infinity" and more, its getting to a point where its posted atleast bi-weekly.. 😥 -
github95487y@JoshBent shit... That much frequent.. we should have moderator system.. so, if u were it, u could have deleted my rant instantly.. leading me to another rant ranting for deletion of my rant in devrant..
-
@github Don't take it that rough, you just happen to have used the same case many repost "bots" on here abused.. 😅
-
That's exactly the behaviour I would expect to see, knowing how the parseInt function works.
Documentation. Read it. -
@Tale-Of-X9 why would one ever expect NaN to be equal to NaN? Would you expect the following to be true?
Math.sqrt(-1) === (0 / 0); // ???
Math.sqrt(-1); // NaN
0 / 0; // NaN -
@github I put quotation marks around bots to prevent that question, but what I meant was that certain people are straight up acting like bots by just going everyday to the one specific subreddit and post that content to devrant or by just searching for older posts, saving those in lower quality and reposting them. But I wouldn't go as far as saying there isn't any actual bots, because creating one for devrant is one of the easiest tasks.
Related Rants
Basically,
1+infinity = 1
But
infinity + 1 = NaN
My entire maths fundamental shuttered by the beautiful JS language....
undefined
js
javascript
parseint