JavaScript unary operatorsUnary operators in JavaScript are unique operators that consider a single input and carry out all possible operations. The Unary plus, unary minus, prefix increments, postfix increments, postfix decrements, and prefix decrements are examples of these operators. These operators are either put before or after the operand. The unary operators are more effective in executing functions than JavaScript; they are more popular. Unary operators are flexible and versatile since they cannot be overridden. Types of unary operatorsOne value is the focus of unary operators. The unary functions and their descriptions are listed in the following table:
Unary operator's descriptionThe multiple operators use javascript to show the definition, syntax, example, and description. Unary plus (+) operatorThe simple plus symbol (+) is the unary plus operator. The unary addition has no effect when put in front of a number. Syntax The following unary plus operator shows the functionality with the value. The following table outlines the rules used by the Number() function when the unary plus operator is applied to a non-numeric value:
Examples The following examples use to addition operator using the variable operand and unary plus operator. Example 1: the given example shows the basic operation of the unary plus (+) operator with the operand. Here, we use a simple plus sign with the numeric data. Output The unary plus operator data is shown as an output. Example 2: the following example shows the basic operation of the unary plus (+) operator with the operand. Here, we need a function with the "this" keyword for the basic value. Output The unary plus operator data is shown as an output. Unary minus (-) operatorA single minus sign (-) is the unary minus operator. A number is negated when the unary minus operator is used on it. Syntax The following unary minus operator shows the functionality with the value. The unary minus operator cancels a value when used to a non-numeric value after converting it to a number according to the same guidelines as the unary plus operator. Examples The following examples use to subtraction operator using the variable operand and the unary minus operator. Example 1: the given example shows the simple operation of the unary plus (-) operator with the operand. Output The unary minus operator shows as output data. Example 2: the following example shows the basic operation of the unary minus (-) operator with the operand. Here, we need a function with the "this" keyword for the basic value. Output The unary minus operator data shows as an output. Unary Logical Not(!) operatorUnary logical not operator works the logical operation and Boolean output. It converts the value in the negative data and shows the Boolean value as an output. Example The given an example displays the basic operation of the unary Logical Not(!) operator With operand. Here, we need a function with the not operator and the input data. Output The unary logical, not operator, data is shown as an output. Prefix Unary increment (++) operatorJavascript unary increment operator increments the value before operation. This operator increments the value by one of the original and default values. This operator needs an operand to add the value and return the additional value. Syntax The following unary increment operator shows the functionality with the value. The unary increment operator cancels a value when used to a non-numeric value. It works on the numerical input values for the addition operation. Examples The following examples use addition by one (increment) operator using the variable operand and unary increment operator. Example 1: The given example displays the basic operation of the unary increment (++) operator with the operand. Output The unary incremental operator data shows as an output. Example 2: The given example displays the basic operation of the unary increment (++) operator with the operand. Here, we need a function with the "this" keyword for the basic addition operation and its output value. Output The unary incremental operator data shows as an output. Prefix Unary decrement (--) operatorJavascript unary decrement operator is used to decrement the value before operation. This operator decrements the value by one of the original and default values. This operator needs an operand to add the value and return the additional value. Syntax The following unary decrement operator shows the functionality with the value. Example The given example displays the basic operation of the unary decrement (--) operator with the operand. Output The unary decrement operator data shows as an output. Postfix Unary increment (++) operatorJavascript unary increment operator increments the value after the operation. This operator is used to increment value by one of the default values after the mathematical operation. Syntax The following postfix unary increment operator with the value. The unary increment operator cancels a value when used to a non-numeric value. The original variable can be incremented by one. Example The given example displays the operation of the postfix unary increment (++) operator with the operand. Output The unary incremental operator data shows as an output. Postfix Unary decrement (--) operatorJavascript unary decrement operator decrements the value after the operation. The operator works to decrement the value by one of the default values after the mathematical operation. Syntax The following postfix unary decrement operator with the value. Example The given example displays the operation of the postfix unary decrement (--) operator with the operand. Output The postfix unary decremental operator data shows as an output. Unary bitwise not (~) operatorIt is a logical operator to operate binary, not an operation using invert functionality. It works for inverting the input value of the script. Example The given example displays the operation of the unary bitwise not (~) operator with the operand. Output The unary bitwise not operator data shows as an output. Unary delete operatorThe deletes operator is a unary operator in javascript to delete the specific index of the array. It does not affect the operand, variable, and other functionality. The operator uses to delete a specific index before the operand with a variable and shows values as an output. Example The given example displays the operation of the unary delete operator with the operand. Output The unary delete operator and show operand as an output. Unary void operatorThe void operator is a unary operator but uses as an expression to return the output of the undefined input data. The empty return type shows the function's information in the output tab. The void operator contains no input data and shows an undefined value. Example The given example displays the operation of the unary void operator with the javascript function. Output The unary void operator and show operand as an output. ConclusionThe unary operators help to use different operations and functionality simply. It is easy for developers and users to execute javascript values.
Next TopicFilterable Gallery Using Filterizr.js
|