DEV Community

Discussion on: Share a code snippet in any programming language and describe what's going on

Collapse
 
warwait profile image
Parker Waiters

JavaScript

parseInt("fuck", 16);
👉 15
parseInt("fart", 16);
👉 250
parseInt("shit", 16);
👉 NaN
Enter fullscreen mode Exit fullscreen mode

JavaScript will parse a string until it gets to an character it can't parse and then return the value. In this example, by parsing hexadecimal, we get f in the first example, fa in the second, but nothing in the third because s isn't a valid hex character.