Hello guys, welcome to our series Java script, we are going to continue our topic from previous segment. Today we are going to see assignment operators, assignment operators are comparatively easy to understand. What happens in assignment operator? When we have to assign some values then we perform some operation with it and assign those values or without performing any operation also we can assign those values.
So first is our equal to operator, so what is in assignment? We have already seen equal to, when we have to assign any value to the variable that time we use equal to. We have done similar thing in arithmetic also, x= 10, y=20, in comparison also we have done the same thing, even in bitwise and logical also we have done similar things.
Means whenever we assign value to variable we use equal to , so here we will generate a new program, (23 seconds gap) so this our assignment operators, ( 4 seconds gap), okay, assignment operator, var x=5, so here I have assigned a value to operator, now let’s go back to slide, here we have 5 things, there are some signs, some operators associated with assignment.
For example, plus, minus, multiplication, divide and modulus. So all these operators means first assign so and so value and then perform the operation, means if I take plus equal to(+=), the execution will be like this, if a+=b means a equal to a plus b, I will repeat once again a+=b means a equal to a plus b. so what happens because of this when we assign a values, previous value also get added.
Similarly, a-=b means, a equal to a-b , no I will write something here in sublime text, let’s say I take a value, we have taken variable x as 5 now I will take var y= 7, so here we will first add heading, assignment operator, in that I will write (4 seconds gap), document.write, here I have to assign a value so first we will take example of a plus equal to b, added assignment, so it will be like this, assignment x plus equal to y here we will write plus x+=y, okay , so here plus equal to y means x equal to x plus y.
Here how does x+=y , here I have written in comment x equal to x plus y so whenever you see x+=y then how you have to interpret it? you have to go with x =x+y , what answer will we get? Let’s I write here and comment multi line, so value of x is 5 +7 so here will be x= 5+7 so x= 12 will be generated. So x= 5+7 means value of x is 5 and value of y is 7 so 5+7 will be performed and the value will be assigned to x only.
So after this line whenever I write document.write x so value of x will not be 5 it will be 12, because I have performed summation of 5+7 but along with that I have assigned to x. if I have to keep it independently then I won’t write x+=y, here I will simply write x+y, like this. So now I will get 12, but it is not getting assigned, if you have to assign also, then you will write x+=y. I will save this assignment program, okay so here x+=y is 12, means x plus y has been performed but along with that the value has been assigned to x.
If you have to verify then we can do it here, document.write br and here (3 seconds gap) plus x, here you can see value of x is 12, previously its value was 5 which now has changed. Now if I perform x+y then you can see value of x+y is 12 but value of 5 has changed to 5, means assignment is not getting performed, only x+y is performed.
So for that what we will do here? X+=y, so our answer will be 12, so I hope it is clear to you all how assignment operator works. Exactly same way we will perform here subtraction, okay, then comes multiplication, then comes division, okay so we will perform all the operations. So you can see here, 12,5,35,5 is our output.
Reason behind that, initially our value was 5, when we considered 5+7 , x became 12, now when I am coming to this line the value of x has already been changed to 12, so when I come here and perform x-y, then value of x is 12 and value of y is 7, so value of x will be 5. Okay therefore here I am getting 5 as x-y and that value has been assigned to x.
Now we will come here were multiplication will be performed , so between slash start star slash, x=x*y, then x equals to, we always have to take previous value not the initial value, so previous value is 5, and value of y is not getting changed it is 7, so x= 5*7, i.e. 35 so x equals to 35, now when I am performing division, then what we are getting? X= x/y so x equal to, what is the value of x it is 35 i.e. 35 divide by, what is the value of y, it is 7, so 35 divide by 7 so x equals to 5.
So you must have seen whenever we performed assignment operator, so I have written all the calculations, everything is getting performed in same manner. So operation is getting performed between x and y and the value is assigned to x. i.e. x, x, x, and x, and every time the updated value is used.
Coming back to slide so this was our assignment operator, last is modulus operator, so we will see that also, so assignment x modulus, before checking we will perform calculation here itself so that we will know if it is right. So here x equals to x modulus y, so x is 5, modulus i.e. 7, so if we divide 5 by 7, so we will get some remainder. Okay, so our answer will be in point and our remainder will be 5. So here our remainder should be 5 according to calculation and here we are getting 5.
So because of 7, answer will be 0.7 and after modulus the remainder will be 5so that’s why we are getting 5 as our answer. So these were our assignment operators, we have covered all the assignment operators. So guys I request you to practice all the logical and assignment operators and perform it so that it will be much clear to you. If you have any questions or queries while performing the practical of logical and assignment operators then you can tell us on forums.learnvern.com we will revert back with solution to your questions.
In next segment we will continue special operators.
Thank you ( video duration 10 minutes 26 seconds)
good course material
Pasalapudi Pujita Sri Naga Santhoshi
they has clearly explained and easily understand to all
Superb and amazing 😍🤩 enjoyable experience.
This is by far the most comprehensive tutorial I ever come across. I was really excited to discover this amazing tutorial, but unfortunately couldn't continue due to keypad noise which I'm allergic to
VAISHNAVI RAJESH CHALKE
it helps me to clear my basic conceptual knowledge
Thank you! I enjoyed the course; I learned so much.