In this js quiz, you need to find sum of object and variable value. But there is also one thing in it. We are also incrementing a value.
So, First we are declaring a num variable using let keyword and assign number value 5 to it.
First one is just a num key in obj with value 10.
And second one, value key with increment operator num
At, last we are adding three values. Which are…
obj.value + obj.num + num
And assign it to result variable, created using let keyword. So, what will be the result value. Let’s find out.
Now, you are thinking why the answer is 22.
Let me explain you step by step. So, you can understand the reason behind it.
First, we are calling obj.value for adding and it’s value is 6 because we have used an increment operator at prefix. So it increment the value before use.
Note : num in value key is a num variable which is declared at top.
In second step, we are adding a obj.num whose value is 10 and do not confuse with num variable. Both are different, one is a key in object and another one is a variable.
Now at last we are using num variable and it’s value is 5 but as we are already running a increment operator on it using obj.value. It’s value become 6.
So, it’s something look like it.
let result = 6 + 10 + 6
Finally, it gives us the result of 22.
I hope you understand the concept and logic behind it.
But wait, i have something more for you –
- JS Quiz – What really the array values method return
- JavaScipt Quiz – What is the length of String Split Method
And last but not the least, don’t forget to like, comment and share. It gives us a morale boost to remain to continue. Also, join our Facebook Page
If you have any questions, please feel free to ask me in the comment section and also let me know if you have any suggestions. As suggestions are always welcome.