Operators in javascript with example
ExampleAssign values to variables and add them together: Show
let x = 5; // assign the value 5 to x Try it Yourself » The assignment operator ( The addition operator ( The multiplication operator ( Types of JavaScript OperatorsThere are different types of JavaScript operators:
JavaScript Arithmetic OperatorsArithmetic operators are used to perform arithmetic on numbers:
Arithmetic operators are fully described in the JS Arithmetic chapter. JavaScript Assignment OperatorsAssignment operators assign values to JavaScript variables.
The addition assignment operator ( Assignment operators are fully described in the JS Assignment chapter. Adding JavaScript StringsThe Example let text1 = "John"; The result of text3 will be:
Try it Yourself » The Example let text1 = "What a very "; The result of text1 will be:
Try it Yourself » When used on strings, the + operator is called the concatenation operator. Adding Strings and NumbersAdding two numbers, will return the sum, but adding a number and a string will return a string: Example let x = 5 + 5; The result of x, y, and z will be:
Try it Yourself » If you add a number and a string, the result will be a string! JavaScript Comparison Operators
Comparison operators are fully described in the JS Comparisons chapter. JavaScript Logical Operators
Logical operators are fully described in the JS Comparisons chapter. JavaScript Type Operators
JavaScript Bitwise OperatorsBit operators work on 32 bits numbers. Any numeric operand in the operation is converted into a 32 bit number. The result is converted back to a JavaScript number.
The examples above uses 4 bits unsigned examples. But JavaScript uses 32-bit signed numbers. Bitwise operators are fully described in the JS Bitwise chapter. Test Yourself With ExercisesWhat are the 4 types of JavaScript operators?JavaScript includes operators that perform some operation on single or multiple operands (data value) and produce a result. JavaScript includes various categories of operators: Arithmetic operators, Comparison operators, Logical operators, Assignment operators, Conditional operators.
What is the or operator in JavaScript?The logical OR ( || ) operator (logical disjunction) for a set of operands is true if and only if one or more of its operands is true. It is typically used with boolean (logical) values.
What are the different types of operator in JavaScript?There are various operators supported by JavaScript:. Arithmetic Operators.. Comparison Operators.. Logical Operators.. Assignment Operators.. Ternary Operators.. typeof Operator.. What are operators explain with example?In computer programming and at the command line, an operator is an object that is capable of manipulating a value or operator. For example, in "1 + 2", the "1" and "2" are the operands and the plus symbol is the operator.
|