less
  1. less-operations

Operations - (Less Basics)

In this tutorial, we'll discuss some less basic operations in programming. These operations are not as commonly used as basic operations like arithmetic operations or logical operations, but they are still important to understand.

Bitwise Operations

Bitwise operations operate on the individual bits of a binary number. There are several bitwise operations available, including:

  • & (Bitwise AND): Returns a binary number where each bit is set to 1 if the corresponding bit is also 1 in both operands.
  • | (Bitwise OR): Returns a binary number where each bit is set to 1 if the corresponding bit is 1 in either operand.
  • ^ (Bitwise XOR): Returns a binary number where each bit is set to 1 if the corresponding bits are different in the two operands.
  • ~ (Bitwise NOT): Returns a binary number where each bit is inverted (0s become 1s and 1s become 0s).
  • << (Left Shift): Shifts the bits of a binary number to the left by a specified number of positions.
  • >> (Right Shift): Shifts the bits of a binary number to the right by a specified number of positions.

Ternary Operator

The ternary operator is a shortcut for an if-else statement. It has the following syntax:

condition ? expression1 : expression2

The condition is evaluated first. If it is true, expression1 is returned. Otherwise, expression2 is returned.

Type Operators

Type operators check the type of a variable. There are two type operators in most programming languages:

  • typeof: Returns a string indicating the data type of a variable.
  • instanceof: Returns true if an object is an instance of a specified class.

Null Coalescing Operator

The null coalescing operator is a shortcut for checking if a variable is null and returning a fallback value if it is. It has the following syntax:

variable ?? fallbackValue

If variable is null, fallbackValue is returned. Otherwise, variable is returned.

Use

These less basic operations can be used to perform more complex operations or to write shorter and more concise code. Understanding these operations can also help you read and comprehend code that uses them.

Summary

In this tutorial, we discussed some less basic operations in programming. We covered bitwise operations, the ternary operator, type operators, and the null coalescing operator. With this knowledge, you can now use these operations to write more advanced code and understand code that uses them.

Published on: