Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära Operatorer och Jämförelser | Sektion
Javascript-Grunder

Operatorer och Jämförelser

Svep för att visa menyn

Operators let you perform calculations and compare values. Types of Operators

  • Arithmetic: +, -, *, /, %;
  • Assignment: =, +=, -=;
  • Comparison: ==, ===, !=, !==, >, <, >=, <=.
12345678910111213
// Comparing with == (loose equality) vs === (strict equality) console.log(5 == "5"); // true, because == does type conversion console.log(5 === "5"); // false, because === checks both value and type // Not equal operators console.log(5 != "5"); // false, because == type conversion makes them equal console.log(5 !== "5"); // true, different types // Greater than, less than, greater than or equal to, less than or equal to console.log(7 > 3); // true console.log(2 < 1); // false console.log(4 >= 4); // true console.log(9 <= 10); // true

When you use comparison operators, JavaScript evaluates the values as either truthy or falsy. A truthy value is any value that is considered true when evaluated in a Boolean context, while a falsy value is one that is considered false. The most common falsy values in JavaScript are:

  • false;
  • 0 (the number zero);
  • "" (empty string);
  • null;
  • undefined;
  • NaN (not a number).

All other values are considered truthy.

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 1. Kapitel 6

Fråga AI

expand

Fråga AI

ChatGPT

Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal

Operatorer och Jämförelser

Operators let you perform calculations and compare values. Types of Operators

  • Arithmetic: +, -, *, /, %;
  • Assignment: =, +=, -=;
  • Comparison: ==, ===, !=, !==, >, <, >=, <=.
12345678910111213
// Comparing with == (loose equality) vs === (strict equality) console.log(5 == "5"); // true, because == does type conversion console.log(5 === "5"); // false, because === checks both value and type // Not equal operators console.log(5 != "5"); // false, because == type conversion makes them equal console.log(5 !== "5"); // true, different types // Greater than, less than, greater than or equal to, less than or equal to console.log(7 > 3); // true console.log(2 < 1); // false console.log(4 >= 4); // true console.log(9 <= 10); // true

When you use comparison operators, JavaScript evaluates the values as either truthy or falsy. A truthy value is any value that is considered true when evaluated in a Boolean context, while a falsy value is one that is considered false. The most common falsy values in JavaScript are:

  • false;
  • 0 (the number zero);
  • "" (empty string);
  • null;
  • undefined;
  • NaN (not a number).

All other values are considered truthy.

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 1. Kapitel 6
some-alt