AWI thanks, I understand that but if arr = ; arr.length = 1
arr =  length should be 2 because we have two numbers in the same array,,,, Why it is considering each individually 😑 that was my point..!!
This is the flow:
var arr = ;
arr =arr.length; //this stores 0 as the first value of the array with a length of 1.
arr = arr.length + 1; //arr.length is 1 added to 1 to give a value of 2
By now arr has this arr =[0, 2] with the length of 2
var x = arr.length + arr;
arr.length is 2, while arr is 2
So, x = 2+2 which is 4.
Thanks David Carroll ,you all are so nice to me. Love you all😍.
It takes some time to be clear, everyone answered well enough to be understood but I had no patience that time. This is a fault of mine to learn everythings in a moment.
If I read it now, everyone answered clearly😍
Tahir Usman I'm assuming you might be learning to program for the first time.
If so, then, it's easy to lose your patience on concepts in the beginning. It does help to walk away and return when you've cleared your mind.
The challenge is getting your mind to think like an imperative programmer, which is much different from a declarative programmer.
Rest assure... there will be a point where all this effort to keep concepts straight in your mind will be effortless.
I swear, I can program with less effort than it takes me to write this response in English - my native language. 🤣
You'll get there. Just keep asking for help from the community. 😉👌
Initially the length of arr is zero since it is empty, and zero in an integer value.
arr = arr.length; //assigning the first index of array the value of 0.
arr = arr.length+1; //arr.length = 1 (from arr), therefore arr.length+1 = 1+1 = 2.
var x = arr.length+arr; //arr.length = 2 (ie arr and arr), and the value stored at index 2 is 2 (from arr=2), therefore arr.length + arr = 2+2 = 4.
Tahir Usman it is considered for the whole array. There are different ways of initializing arrays and the method you use is one of them. When you give an index a value, it automatically appends itself to the array giving the array a new length.
Assignment operation is a two steps operation :
step 1: evaluate the right side of =.
step 2: assign the value obtained in step 1 to the variable at left side.
In the statement "arr=arr.length;", the value of arr. length is fetched first and it returns 0 as array is empty at that point. Then 0 is stored at arr and now length is 1. Only after completion of entire statement arr. length becomes 1. Same with the next statement, first the value of arr. length is accessed which is 1 and then 1+1=2, 2 is stored in arr.
Awesome dialog in this thread. I'm only sorry I missed it 27 days ago.
Mad props to Emmanuel Joshua, AWI, nidhi for the patience and ability to give such clear and well written explanations based on the feedback focusing on the remaining points of confusion. 👏
I'd like to give even greater props to Tahir Usman for pressing on with where the confusion remained. It was clear that he was trying to wrap his head around the explanations provided. But rather than leaving it be, he did his best to articulate exactly where the disconnect was in his mind.
I hope the understanding was made clear with the response from nidhi. However, if it's still not clear, please let us know.
It's great for me to see dialogs like these from time to time because it's easy to forget what might not make sense for people in the process of learning these concepts.
Well done to all involved. 🤓👌
Tahir Usman it's how you choose to initialize your array. Yours is an empty or null array, so that later you can give each indexes a value.