Forem

Cover image for Operadores Relacionais (Parte 1)
ananopaisdojavascript
ananopaisdojavascript

Posted on • Originally published at ananopaisdojavascript.hashnode.dev

3 1

Operadores Relacionais (Parte 1)

O que são operadores relacionais?

São operadores que criam relações entre variáveis, valores e expressões e geram resultados lógicos (verdadeiro ou falso). Em outras palavras, são operadores de comparação.

/*  >   Maior que  */
/*  >=  Maior ou igual a  */
/*  <   Menor que  */
/*  <=  Menor ou igual a  */
/*  ==  Igual a  */
/*  !=  Diferente de  */
/*  ===  Exatamente igual a  */
/*  !==  Exatamente diferente de  */
Enter fullscreen mode Exit fullscreen mode

Cuidado com != e ==!!!!!

É bom tomar cuidado com esses operadores! Existem algumas diferenças entre eles e os operadores !== e ===.

// !=  Compara valores
// !== Compara valores e tipos
// ==  Compara valores
// === Compara valores e tipos
Enter fullscreen mode Exit fullscreen mode

Vamos a um exemplo:

2 == "2"; // true
Enter fullscreen mode Exit fullscreen mode

Por que o resultado dessa comparação é true? Porque comparamos apenas os valores, ainda que sejam tipos diferentes (number e string).

2 === "2"; // false
Enter fullscreen mode Exit fullscreen mode

Por que o resultado dessa comparação é false? Porque apesar de os valores serem iguais, os tipos são diferentes (string não é a mesma coisa que number). O raciocínio acima também serve para != e !==.

2 != "2"; // false (considera somente o valor)
2 !== "2"; // true (considera o valor e o tipo)
Enter fullscreen mode Exit fullscreen mode

E aí? Gostaram? Até a próxima anotação! 😊

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay