What do you understand by Operators?
Operators is defined as how we perform actions on Variables and Values. We can perform multiple actions on single or multiple operands (value) and produce a result. For example 5+ 4, where + sign is an operator and 5 is left operand and 4 is right operand. + operator adds two numeric values and produces a result which is 9 in this case. Operator helps to virtualise our actions when a variable has been assigned a value.
- Arithmetic Operators
- Comparison Operators
- Logical Operators
- Assignment Operators
- Conditional Operators
Arithmetic operators are used to perform mathematical operations between numeric operands.
However, the + operator performs concatenation operation when one of the operands is of string type. This is often regarded as “String Concatenation”.
The following example shows how + operator performs operation on operands of different data types.
Comparison operators helps to compare two operands and return Boolean value true or false. For example if you building an app and you want to compare two things if it’s true or false. Or you want to confirm if something was done, the comparison operator is used.
Logical operators are used to combine two or more conditions. There are sometimes you want to perform two or more actions to determine if it’s true or false. However, Logical operator helps us to perform combine multiple conditions in one statement.
Assignment operators is used to assign values to variables. Basically it’s major purpose is to ensure that when a variable is been declared a value, It’s important that the variable responds.
Ternary Operator is regarded as a special operator. I often call it the Short form to writing if Statements(). However, value is assigned to a variable based are based on some condition.
Ternary operator starts with conditional expression followed by ? operator. Second part ( after ? and before : operator) will be executed if condition turns out to be true. If condition becomes false then third part (after :) will be executed.
That’s a wrap for now!😊
I hope you are able to under what Operators are, and what they help us do.😊
In the next series i will be talking about Variables.