"b" + "a" + +"a" + "a" ? Banana? What ?

"b" + "a" + +"a" + "a" ? Banana? What ?

JavaScript is one of the most important programming languages in the world. Whether you're a front-end or back-end developer, it's essential to be aware of its quirky—and sometimes funny—behaviors. In this article, I’ll highlight some of these intriguing aspects. Let’s dive in!


Math.min and Math.max

When you try to do something like the snippet code below the return is true. The most interesting point is that the Math.min() returns the special number in Javascript named Infinity, and the Math.max() returns -Infinity.


Not A Number

In JavaScript, 'Not A Number' is abbreviated as NaN. It's a special value used to represent undefined or unrepresentable numerical results. First, it's important to note that NaN is typed as a number in JS. When you concatenate any object with a string, the result is NaN. Interestingly, comparing two NaN values will yield false! ?? So, remember: NaN is not actually a number! ??


parseInt

This is quite funny! The parseInt method takes two parameters: the first is the string value, and the second is the radix (or base). Essentially, this method attempts to convert the input to the specified base. The funny behavior occurs when you pass null and any base between 24 and 30, leading to the unexpected result shown in the code below.


"b" + "a" + +"a" + "a";

To the end, this is my favorite ??, look at the result of the result the expression in the snippet below:

There are many quirky and funny behaviors in JavaScript, and as JS developers, it's essential to understand them to prevent errors. I hope you enjoy this and thanks for your time!


Felipe Dumont

Senior Front-end Software Engineer | Mobile Developer | ReactJS | React Native | TypeScript | NodeJS

5 个月

Very Interesting, nice share.

回复

要查看或添加评论,请登录

Davi Silva的更多文章

  • React Hooks? Ok, mas por que?

    React Hooks? Ok, mas por que?

    No dia 6 de fevereiro de 2019, foi lan?ada a vers?o 16.8 do React, introduzindo os hooks.

  • JavaScript: var, let, and const

    JavaScript: var, let, and const

    If you're a JavaScript developer, you probably use , , or in your code. But do you really know what's happening under…

  • JavaScript, React ? Olha lá hein!

    JavaScript, React ? Olha lá hein!

    Nos últimos anos (quase quatro anos), venho trabalhando exclusivamente com desenvolvimento front-end, escrevendo código…

    4 条评论
  • Entendendo atributos privados no JavaScript/TypeScript

    Entendendo atributos privados no JavaScript/TypeScript

    O JavaScript, sendo uma linguagem de tipagem dinamica, realiza uma inferência automática de tipos. Isso significa que…

  • Understanding mutability and infer in TS

    Understanding mutability and infer in TS

    In this article, we will explain how Typescript works with mutability and inferring typings when you declare variables.…

  • Seven ways to remove elements from Arrays in JS

    Seven ways to remove elements from Arrays in JS

    It's most common when we develop code, in front or in the backend, to need to manipulate data from arrays removing…

  • 5 Javascript concepts every developer should know

    5 Javascript concepts every developer should know

    Every JavaScript developer should be familiar with these features that I am going to show in this article - modern…

  • Capital letters? Why ?

    Capital letters? Why ?

    Do you work with React? Do you know why React components need to start with capital letters? In JSX, React components…

  • TTFB, TTI, and FCP: Do You Know What These Acronyms Mean?

    TTFB, TTI, and FCP: Do You Know What These Acronyms Mean?

    When discussing front-end applications built with React, we often encounter two primary types: SPAs (Single Page…

  • SOLID no React Native - parte 2

    SOLID no React Native - parte 2

    O acr?nimo SOLID trata de um conjunto de cinco regras no design de software. Com essas regras, podemos criar software…

    2 条评论

社区洞察

其他会员也浏览了