57 extra and trailing comma in arrays - Javascript Tutorial 2018

Published: 02 September 2017
on channel: Ricky Wahowa (rwahowa)
591
6

The Full #Javascript #tutorial for #beginners :

http://bizanosa.com/js

Wath full HTML,CSS and Javascript tutorial here : http://bizanosa.com/sp/learn-html-css...

Javascript Tutorial 2018




This is a Javascript tutorial from scratch for any beginner. Use the above link to watch the full JS video tutorial..

Next Video:    • 58 JS Array comma examples -  Javascr...  
Previous Video:    • 56 Array literal -  Javascript Tutori...  





So, in these couple of videos, we’ve been looking at array literals.

And in the last video, I told you that we were going to look at this trailing comma.

So what happens if you have a trailing comma in your array? Now, I have this example, this example here.

Now this example will help us understand what trailing this one and these extra commas, what effect do they have in our array? So if you look at this, you can see we have this element Joe.

And then we also have one comma that ends it and then another comma.

So here, we have an element.

Here there’s an element.

And the element that is here is undefined.

It is there and it will be counted as an existing element even though there’s no element that has been declared in there.

This extra comma means that there’s an element in here.

It is just not been defined yet.

Now, we also have this trailing comma.

Now the trailing comma means that this is supposed to end this array element.

But this one will be ignored.

So it doesn’t mean that there’s an element which is missing here.

So, this one will be ignored.

So the trailing comma is ignored but the commas that are within other elements will be treated as an element which is undefined.

Let me come back here and we’re going to use this, in fact this is a good example because we already have this.

So we can use this to see the length.

So if I come here and I add another comma here, so currently if I do that, let’s see.

This tells us that our array has a length of 3.

So, let me add another comma here.

And if I add a comma, and then display the length, you’ll see right now we have 4.

If also I come here and I add another comma, then display that, you’ll see we have 5 elements.

And then, now let’s see what elements are in there.

Now, 0,1.

So let’s see at 1, what value do we have for this particular array.

So if I display, you’ll see it’s undefined.

If I look at 0, display, it gives us the result for John which is this one.

And then, this is 0, 1, 2, 3.

Now the element at index 3, that is also undefined which is here.

But, even if I have this extra comma here, you see it doesn’t change anything.

Let me take this again.

Control+C.

And just put it here.

Then display.

The length is 5.

Even if I remove this, it will not change.

It’s not going to change the length of our array.

So if I display, our array is still 5.

So, this trailing comma is ignored.

But don’t always put this one because it may cause issues in older browsers.

So just remove that.

Let the last element just end without any comma.

So any element you put in here, if you don’t add anything in this comma, within this comma, it will mean that there’s an element which is undefined in this section.

So in this video, we have taken a look at the effect of extra commas and the effect of trailing commas in the arrays.

So let’s continue on in the next video from here.


GET SOCIAL WITH ME:
FACEBOOK:   / rwahowa  
INSTAGRAM:   / rwahowa  
TWITTER:   / rwahowa  
VIMEO: https://vimeo.com/bizanosa/
WEBSITE : http://rwahowa.com


On this page of the site you can watch the video online 57 extra and trailing comma in arrays - Javascript Tutorial 2018 with a duration of hours minute second in good quality, which was uploaded by the user Ricky Wahowa (rwahowa) 02 September 2017, share the link with friends and acquaintances, this video has already been watched 591 times on youtube and it was liked by 6 viewers. Enjoy your viewing!