Skip to content

JavaScript Symbols for Performing Operations

Comprehensive Learning Hub: A versatile educational platform that equips learners in various fields, including computer science and programming, traditional school subjects, professional development, business management, software applications, competitive exam preparation, and numerous others.

JavaScript Symbols for Performing Operations
JavaScript Symbols for Performing Operations

JavaScript Symbols for Performing Operations

JavaScript, a versatile programming language, offers a rich set of operators that enable developers to perform various actions on values and variables. These operators fall into different categories, each serving a unique purpose.

In this article, we will delve into the various types of JavaScript operators and provide examples for better understanding.

## Arithmetic Operators

Arithmetic operators perform basic mathematical operations such as addition, subtraction, multiplication, division, modulus, and exponentiation.

```js 5 + 3 // 8 10 - 4 // 6 2 * 3 // 6 8 / 2 // 4 10 % 3 // 1 (remainder) 2 ** 3 // 8 (2 raised to the power of 3) ```

## Assignment Operators

Assignment operators assign values or results of expressions to variables.

```js let x = 5; x += 3; // equivalent to x = x + 3; x is now 8 ```

## Comparison Operators

Comparison operators return a Boolean after comparing values.

```js 5 == '5'; // true (loose equality, converts types) 5 === '5'; // false (strict equality, no type conversion) 3 > 2; // true 4 <= 4; // true ```

## Logical Operators

Logical operators combine Boolean logic.

```js true && false; // false true || false; // true !true; // false ```

## Bitwise Operators

Bitwise operators work with binary digits (32-bit integers).

```js 5 & 3; // 1 (binary 0101 & 0011) 5 | 2; // 7 (binary 0101 | 0010) ~5; // -6 (bitwise NOT) 5 << 1; // 10 (left shift) ```

## BigInt Operators

BigInt operators operate on BigInt for arbitrarily large integers similarly to numbers but specially typed.

```js const big1 = 9007199254740991n; const big2 = 10n; big1 + big2; // 9007199254741001n ```

## String Operator

The string operator is mainly used for concatenation.

```js 'Hello ' + 'World'; // "Hello World" ```

## Conditional (Ternary) Operator

The conditional (ternary) operator is a shorthand for if-else statements.

```js let age = 18; let canVote = age >= 18 ? 'Yes' : 'No'; // "Yes" ```

## Comma Operator

The comma operator evaluates multiple expressions but returns only the last one.

```js let a = (1, 2, 3); // a is 3 ```

## Unary Operators

Unary operators operate on a single operand, performing operations like negation, logical NOT, type checking, and increment/decrement.

```js typeof 42; // "number" !false; // true ++x; // increments x by 1 ```

## Relational Operators

Relational operators compare values, often involving sorting or order.

```js 5 < 10; // true 'a' > 'b'; // false ```

## Chaining Operators

Chaining operators allow safe access to nested properties or calls without errors.

```js let obj = { a: { b: 2 } }; obj?.a?.b; // 2 obj?.c?.d; // undefined (no error) ```

Understanding these operators will empower developers with flexible tools for coding logic, calculations, and expressions. In our next article, we will discuss operator precedence in JavaScript.

[1] - [MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators) [3] - [W3Schools JavaScript Operators](https://www.w3schools.com/js/js_operators.asp) [5] - [GeeksforGeeks JavaScript Operators](https://www.geeksforgeeks.org/javascript-operators/)

Here are two sentences in English language that contain the words 'trie', 'math', 'technology':

  1. In the field of computer science, trie data structures are often used in information retrieval systems, particularly in queries involving technology and mathematics.
  2. A major advantage of using trie data structures in technology-driven industries is their efficiency in handling complex mathematical calculations, such as spelling correction and numerical range queries.

Read also:

    Latest