- Expressions and operators
- Expressions and operators by category
- Primary expressions
- Left-hand-side expressions
- Increment and decrement
- Unary operators
- Arithmetic operators
- Relational operators
- Equality operators
- Bitwise shift operators
- Binary bitwise operators
- Binary logical operators
- Conditional (ternary) operator
- Assignment operators
- Yield operators
- Spread syntax
- Comma operator
- Specifications
- Browser compatibility
- See also
- Found a content problem with this page?
- MDN
- Support
- Our communities
- Developers
- Strict inequality (!==)
- Try it
- Syntax
- Description
- Examples
- Comparing operands of the same type
- Comparing operands of different types
- Comparing objects
- Specifications
- Browser compatibility
- See also
- Found a content problem with this page?
- MDN
- Support
- Our communities
- Developers
- Операторы сравнения и логические операторы в JS
- Пример 2. Оператор не равно
- Пример 3. Оператор строго равно
- Пример 4. Оператор строго не равно
- Пример 5. Оператор больше
- Пример 6. Оператор больше или равно
- Пример 7. Оператор меньше
- Пример 8. Оператора меньше или равно
- Пример 2. Логический оператор OR
- Пример 3. Логический оператор NOT
- Inequality (!=)
- Try it
- Syntax
- Description
- Examples
- Comparison with no type conversion
- Comparison with type conversion
- Comparison of objects
- Specifications
- Browser compatibility
- See also
- Found a content problem with this page?
- MDN
- Support
- Our communities
- Developers
Expressions and operators
This chapter documents all the JavaScript language operators, expressions and keywords.
Expressions and operators by category
For an alphabetical listing see the sidebar on the left.
Primary expressions
Basic keywords and general expressions in JavaScript. These expressions have the highest precedence (higher than operators).
The this keyword refers to a special property of an execution context.
Basic null , boolean, number, and string literals.
Array initializer/literal syntax.
Object initializer/literal syntax.
The function keyword defines a function expression.
The class keyword defines a class expression.
The function* keyword defines a generator function expression.
The async function defines an async function expression.
The async function* keywords define an async generator function expression.
Regular expression literal syntax.
Left-hand-side expressions
Left values are the destination of an assignment.
Member operators provide access to a property or method of an object ( object.property and object[«property»] ).
The optional chaining operator returns undefined instead of causing an error if a reference is nullish ( null or undefined ).
The new operator creates an instance of a constructor.
In constructors, new.target refers to the constructor that was invoked by new .
An object exposing context-specific metadata to a JavaScript module.
The super keyword calls the parent constructor or allows accessing properties of the parent object.
The import() syntax allows loading a module asynchronously and dynamically into a potentially non-module environment.
Increment and decrement
Postfix/prefix increment and postfix/prefix decrement operators.
Postfix increment operator.
Postfix decrement operator.
Prefix increment operator.
Prefix decrement operator.
Unary operators
A unary operation is an operation with only one operand.
The delete operator deletes a property from an object.
The void operator evaluates an expression and discards its return value.
The typeof operator determines the type of a given object.
The unary plus operator converts its operand to Number type.
The unary negation operator converts its operand to Number type and then negates it.
Pause and resume an async function and wait for the promise’s fulfillment/rejection.
Arithmetic operators
Arithmetic operators take numerical values (either literals or variables) as their operands and return a single numerical value.
Relational operators
A comparison operator compares its operands and returns a boolean value based on whether the comparison is true.
Less than or equal operator.
Greater than or equal operator.
The instanceof operator determines whether an object is an instance of another object.
The in operator determines whether an object has a given property.
Note: => is not an operator, but the notation for Arrow functions.
Equality operators
The result of evaluating an equality operator is always of type boolean based on whether the comparison is true.
Strict inequality operator.
Bitwise shift operators
Operations to shift all bits of the operand.
Bitwise left shift operator.
Bitwise right shift operator.
Bitwise unsigned right shift operator.
Binary bitwise operators
Bitwise operators treat their operands as a set of 32 bits (zeros and ones) and return standard JavaScript numerical values.
Binary logical operators
Logical operators implement boolean (logical) values and have short-circuiting behavior.
Nullish Coalescing Operator.
Conditional (ternary) operator
The conditional operator returns one of two values based on the logical value of the condition.
Assignment operators
An assignment operator assigns a value to its left operand based on the value of its right operand.
Unsigned right shift assignment.
Nullish coalescing assignment.
Destructuring assignment allows you to assign the properties of an array or object to variables using syntax that looks similar to array or object literals.
Yield operators
Pause and resume a generator function.
Delegate to another generator function or iterable object.
Spread syntax
Spread syntax allows an iterable, such as an array or string, to be expanded in places where zero or more arguments (for function calls) or elements (for array literals) are expected. In an object literal, the spread syntax enumerates the properties of an object and adds the key-value pairs to the object being created.
Comma operator
The comma operator allows multiple expressions to be evaluated in a single statement and returns the result of the last expression.
Specifications
Browser compatibility
BCD tables only load in the browser
See also
Found a content problem with this page?
This page was last modified on Apr 5, 2023 by MDN contributors.
Your blueprint for a better internet.
MDN
Support
Our communities
Developers
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998– 2023 by individual mozilla.org contributors. Content available under a Creative Commons license.
Strict inequality (!==)
The strict inequality ( !== ) operator checks whether its two operands are not equal, returning a Boolean result. Unlike the inequality operator, the strict inequality operator always considers operands of different types to be different.
Try it
Syntax
Description
The strict inequality operator checks whether its operands are not equal. It is the negation of the strict equality operator so the following two lines will always give the same result:
For details of the comparison algorithm, see the page for the strict equality operator.
Like the strict equality operator, the strict inequality operator will always consider operands of different types to be different:
Examples
Comparing operands of the same type
"hello" !== "hello"; // false "hello" !== "hola"; // true 3 !== 3; // false 3 !== 4; // true true !== true; // false true !== false; // true null !== null; // false
Comparing operands of different types
"3" !== 3; // true true !== 1; // true null !== undefined; // true
Comparing objects
const object1 = key: "value", >; const object2 = key: "value", >; console.log(object1 !== object2); // true console.log(object1 !== object1); // false
Specifications
Browser compatibility
BCD tables only load in the browser
See also
Found a content problem with this page?
This page was last modified on Feb 21, 2023 by MDN contributors.
Your blueprint for a better internet.
MDN
Support
Our communities
Developers
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998– 2023 by individual mozilla.org contributors. Content available under a Creative Commons license.
Операторы сравнения и логические операторы в JS
Примечание. Обратите внимание, что == — это оператор сравнения, а = — оператор присваивания. Не путайте их, иначе возникнет ошибка.
Пример 2. Оператор не равно
const a = 3, b = "привет"; // оператор не равно console.log(a != 2); // true console.log(b != "Привет"); // true
Оператор != возвращает true , если операнды не равны.
Пример 3. Оператор строго равно
const a = 2; // оператор строго равно console.log(a === 2); // true console.log(a === '2'); // false
Оператор === возвращает true , если операнды равны и принадлежат одному и тому же типу. Здесь 2 и ‘2’ — одинаковые числа, но тип данных у них разный.
Примечание. Разница между == и === заключается в том, что:
• оператор == возвращает true, если операнды равны
• оператор === возвращает true, только если операнды равны и имеют одинаковый тип.
Пример 4. Оператор строго не равно
const a = 2, b = "привет"; // оператор строго не равно console.log(a !== 2); // false console.log(a !== '2'); // true console.log(b !== "Привет"); // true
Оператор !== возвращает true , если операнды строго не равны. Это полная противоположность оператору строго равно === .
В приведенном выше примере 2 !== ‘2 ‘ возвращает true . Так происходит потому, что у них одинаковые значения, но разные типы.
Пример 5. Оператор больше
const a = 3; // оператора больше console.log(a > 2); // true
Операто > возвращает true , если левый операнд больше правого операнда.
Пример 6. Оператор больше или равно
const a = 3; // оператор больше или равно console.log(a >= 3); //true
Оператор >= возвращает true , если левый операнд больше правого операнда или равен ему.
Пример 7. Оператор меньше
const a = 3, b = 2; // оператор меньше console.log(a < 2); // false console.log(b < 3); // true
Пример 8. Оператора меньше или равно
const a = 2; // оператор меньше или равно console.log(a
Логические операторы в JavaScript
Логические операторы выполняют логические операции И (AND), ИЛИ (OR) и НЕ (NOT).
Пример 1. Логический оператор AND
const a = true, b = false; const c = 4; // логическое И console.log(a && a); // true console.log(a && b); // false console.log((c > 2) && (c < 2)); // false
Оператор && возвращает true , если оба операнда true , иначе возвращает false .
Примечание. Логические операторы можно использовать и с числами. В JavaScript 0 оценивается как false, все ненулевые значения — true.
Пример 2. Логический оператор OR
const a = true, b = false, c = 4; // логическое ИЛИ console.log(a || b); // true console.log(b || b); // false console.log((c>2) || (c<2)); // true
Оператор || возвращает true , если хотя бы один из операндов true . Если оба операнда false , результат — false .
Пример 3. Логический оператор NOT
const a = true, b = false; // логическое НЕ console.log(!a); // false console.log(!b); // true
Оператор ! возвращает true , если операнд false , и наоборот.
СodeСhick.io - простой и эффективный способ изучения программирования.
2023 © ООО "Алгоритмы и практика"
Inequality (!=)
The inequality ( != ) operator checks whether its two operands are not equal, returning a Boolean result. Unlike the strict inequality operator, it attempts to convert and compare operands that are of different types.
Try it
Syntax
Description
The inequality operator checks whether its operands are not equal. It is the negation of the equality operator so the following two lines will always give the same result:
For details of the comparison algorithm, see the page for the equality operator.
Like the equality operator, the inequality operator will attempt to convert and compare operands of different types:
To prevent this, and require that different types are considered to be different, use the strict inequality operator instead:
Examples
Comparison with no type conversion
1 != 2; // true "hello" != "hola"; // true 1 != 1; // false "hello" != "hello"; // false
Comparison with type conversion
"1" != 1; // false 1 != "1"; // false 0 != false; // false 0 != null; // true 0 != undefined; // true 0 != !!null; // false, look at Logical NOT operator 0 != !!undefined; // false, look at Logical NOT operator null != undefined; // false const number1 = new Number(3); const number2 = new Number(3); number1 != 3; // false number1 != number2; // true
Comparison of objects
const object1 = key: "value", >; const object2 = key: "value", >; console.log(object1 != object2); // true console.log(object1 != object1); // false
Specifications
Browser compatibility
BCD tables only load in the browser
See also
Found a content problem with this page?
This page was last modified on Feb 21, 2023 by MDN contributors.
Your blueprint for a better internet.
MDN
Support
Our communities
Developers
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998– 2023 by individual mozilla.org contributors. Content available under a Creative Commons license.