hey, what’s going on guys stand by her for telesco learnings and in this video tutorial we are going to be understanding the fundamental concept of operators in JavaScript so in a previous couple of videos of this entire JavaScript playlist we’ve seen what are common sort of statements we also saw out of variables and if you have missed those videos you can check it out in this playlist so coming to the today’s topic that is operators in JavaScript so since this is a very big now level tutorial we are going to be taking a little bit of theory and then we will jump to the practical part that is we will see also a program aeverine will be using these operators so starting off javascript operators are symbols which are used to assign values compare values perform arithmetic operations and more so essentially these are symbols okay symbols means plus minus less than equal to greater than equal to and whatnot now the variables are called as operands and the operation to be performed is defined by an operator so in terms of a program it would be something like let’s say we create a variable where a and we say equal to 10 so this equal to is basically an operator it is an assignment operator and what it is doing is it is assigning this value 10 and it is storing it in this variable right so this is that assignment operator for example of course we will see a lot of program examples in some time after this little bit of theory so now there are different types of operators in JavaScript depending upon what activities are what functionality they provide us so we have arithmetic operators we have comparison operators we have logical operators and as the name suggests arithmetic operators perform arithmetic operations that is plus minus multiplication division modulo and whatnot similarly comparison operators as the name suggests is used to perform comparisons between two variables or two entities then we have logical operators which use these comparison operators to give certain results either true or false then we have assignment operators we solve one equal to operator which is a type of assignment operator then we have conditional operators which are used to check for conditions we have string operators we have type operators and bitwise operators so obviously we are
not going to be taking a look at each and every operator in detail in the practical part because that doesn’t make sense and in the further videos as we move out in this series we are anyways going to be covering a lot of operators depending upon the program and depending upon the need so if this was just a little bit of theory on what are operators in JavaScript and the different types of operators now what I’m going to do is I’m just gonna glance through each and every operator type and I’ll just show you the different operators and the meaning and what they do and what you can do is you can pause the screen if
you just want to note them or if you just want to go through them you can just take a screenshot so we’ll go one by one starting off from the arithmetic operator till the bitwise operator okay so these are the arithmetic operators available in JavaScript we have plus-minus multiplication is a star then w have division modulus increment and decrement okay so these are used to perform arithmetic operations let’s move on okay so these are the comparison operators that is a comparison and logical operators are used to testing for true or false okay so you want to test the condition you use comparison operators so again we have the operator we have the description what it is called and we have different examples you can just
pause the video and glance through them and as I mentioned as we move ad in this series they’re going to be using a lot of operators so don’t worry if I’m skipping or moving a little bit faster over here so let’s move on so these are the logical operators which are used in comparison and again they are used to
test for true and false values so we generally use them in if-else and all those control statements which we will see in further videos so again these are the three operators the description that is and or and not and then a little bit of example you don’t need to be worrying about all these we are obviously going to take a look at them in detail in further videos the next is assignment operator which is used to assign values to JavaScript variables or other entities so we have equal to F plus equal to we have minus equal to and then there are examples and what they actually mean moving to add we have a conditional operator which has three different parts that’s why a ternary operator so this is how it looks like we have a variable name we have the condition and depending upon if the condition is true value one will be assigned and if it is false then value two will be assigned so, for example, we have a variable and then we are
saying it is less than 18 if it is less than 18 then it will be too young and if it is not less than 18 then it will be old enough so this is how it looks we will use this in the program in further videos don’t worry so the plus operator also operates as a string operator which means that we can use it with strings so just as the plus operator is used to adding two numerical use we can concatenate two text values using the plus operator okay so, for example, you can see Val text one vertex two and we are seeing text one plus a little bit of space in between and plus text too so this is the output John Doe which comes from two different
variables concatenated in text three then we have type operator which is used to determine the type of data being stored in a variable or an object so depending upon whether it is variable we use type off and if it’s an object we use instance off so if our variable is holding a numeric value that is a number value it ill
return a numeric output okay so we will use this type of an instance of also in further videos and lastly we have the bitwise operators which work on 32-bit numbers and any numeric operand in the operation is converted into a 32-bit number and the result is converted back into JavaScript number okay so for example we have and or not XOR so these are all boolean operators which perform boolean operations so, for example, you can see five and one first is going to be converted into its binary form so Phi
is 0 and 0 1 then we have the and operator and we have 3 times 0 and 1 and then we perform an and operation between them so it’s a logical and operation which is a boolean operation and then we get the result which we convert back to decimal form so these operators are not used a lot and they’re only used in certain specific cases especially if you are designing a circuit which is a digital circuit where you are performing some boolean algebraic operations but they’re not highly used a lot in general scenarios so yeah this was a little bit of theory now let’s jump to the programming part and we will see a couple of examples of operators and we’ll understand the concept of operator precedence and operator associativity ok so as you can see on the screen I have opened up my visual studio code and on the right hand side we have our Google Chrome open and I’m also live so you can see I’ve used the live server plug-in to go live so whatever changes I make over here so let’s see if I change the value of this variable to 3 the result will be immediately reflected without me refreshing it because I’ve also turned on the autosave feature of Visual Studio so anyways as you can see on this screen we are performing a little bit of addition over here so I have variable 1 I have created variable B and then what I’m saying result is equal to a plus B and lastly what I’m doing is I’m just printing out this result in a h1 tag and I’m seeing
result is then I’m using the plus operator so again you can see I’m using an operator to concatenate the result and here I am using the plus operator to perform addition ok so the plus operator is doing two different things when it is strings it is performing concatenation and when it is numbers it is performin addition so now one thing I wanted to talk about is associativity now certain operators have a right-to-left associativity and certain operators have left-to-right associativity so what do I mean by this so when I say right-to-left associativity so in this first case what is happening is the number 3 is beingassigned to variable E right so what is happening is RHS that is right hand side 2 they equal to sign is being assigned to LHS that is this variable e so this is why it is right to left ok so when you’re using this equal to sign it is a right-to-left associativity let’s take another example so let’s say I am again creating one more variable I am saying where C is equal to 6 ok now in the result what I’m going to say is a plus B plus C now the result again has changed you can see 6 plus 3 plus 3 so when you’re using plus sign the associativity is from left to right which means what is happening is first a and B are added then the result of a and B is added with C and then the assignment is happening that is the whole total of a plus B plus C is being
assigned to the result variable because equal to sign has right to left associativity right now you’re wondering why is this relevant now from the previous video we know that JavaScript is loosely typed or weakly typed programming language right which means that we don’t have to declare any kind of data type of the variables so whatever the data is assigned by default the data type is changed so now what I can do over here is if I add a string over here and I add a plus sign over here even this is valid since the
associativity of the plus sign is from left to right so it will start from left and it will see that, okay the first thing to add is a string so it will assume that everything I had of this is also a string so if you see the result is a 3/3
what is it took a as a string let me just change this to something else I’ll see it done man now you can see what is happening is we are getting a result of ton by 3/3 which means that this variable a and B did not get added and we did not get a total of 6 because as I mentioned since the associativity is from left to right all the things are converted to string now so if I change this to 8 you can see the result is 3/8 so they are all concatenated because plus operator operates as a concatenation between strings right now again I’m going to change this same thing what I’m going to do is I’m going to add something over here I’m going to say c plus B and plus ton man but now you can see that the result is 14th and my 38 so C is 6 B is 8 which means that initially we got the total right so this was considered as a number because the associativity of plus is from left to right so it started from left so it says ok sees a number B is a number let’s add it this was added we got a result of 14 now when it came over here that is the program execution came over here it saw this as a string so it’s like ok since this is a string let’s concatenate with the result so 14 was concatenated with done man and everything I had of this was considered as a string so it was also concatenated so a a was three and V was eight which was considered as a string and concatenated and the result was stored in the result variable so this was something which is known as associativity now here is one more thing which is known as precedence and the precedence apply is different to different operators again I have a complete article wherein we have operator precedence and we have associativity and we have all the program examples I’ll link that article in the description you can check it out if you want to check out the theory there’s a lot of content in there but the basic precedence principle is which operator should perform operation first over the next okay so we can have multiple operations in one single line also right so you can see where result 2 is equal to a plus B and now you can say star C so what I am doing over here is I am also performing addition and multiplication so when there are two
different operations in one single expression which operator should operate first depends on the operator precedence because obviously that is going to be changing the value rate so if I say a plus B which happens first that is 8 plus 3 which would be 11 and then 11 into 3 would be 33 right however if I multiply B star C first so B is 8 and C is 6 so 8 6 that would be 48 and 48 plus 3 would be so the output is different right in different cases so that’s what precedence matters so in that theory article which I just told which I’ve shared in the description you can check out the precedence values and in general the arithmetic operators follow our board mass rule which we use in our algebra also that is the multiplication happens first before addition and so on and so forth but I can change that using brackets ok so if I see brackets over here and if I print the result 2 you can see result is 66 however if I remove the brackets there would be 51 now does the result is changed so this was operator precedence okay so that’s it for this video guys I’m gonna wrap it over your because then if I go out and we talk more on operators this video will go a lot Lindy and as I mentioned as we move and we will cover different types of operators and different programs when you will take a look at a lot of practical programs so that’s it for this video guys I hope you like this video if you like this please give it a thumbs up let me know how this video was in the comments and if you haven’t yet subscribed on this channel make sure you subscribe so that you get notified whenever I upload a new video so thanks for watching guys see you guys in the.