Doubts about javascript [closed]

-2

I have some questions about Javascript.

  • What is the array that has the properties? I think I read that the creation is different between var array = []; that var array = new Array();

  • When you create an array of the form var array = new Array(); is it necessary to put some number in the parameters?

  • I remember learning to create an array with undefined elements, but I do not remember the commas very well, it was like var array = [,,,,,,]; I think here there would be 5 elements undefined

  • When we are in the same function and at the beginning of the function they place var algo; , then through the middle of the function they define it as algo = 2; and then at the end as algo = 4; , at the end what happens with The variable? the 2 will be replaced by the 4? , are they concatenated? what happens? , because if I do this with an array ( array[array.length] = "Elemento6"; ), in this case an element is added, but with the variables how are you going?

  • asked by Eduardo Sebastian 20.04.2017 в 12:10
    source

    1 answer

    1

    We are going through steps:

    1-In principle there is no difference between writing var array=[] and var array= new Array() almost never, except in one case, which is when you fill in numbers. Example:

    var numeros = [45];
    

    This creates an array with the number 45 in the 0 position.

    var numeros= new Array(45);
    

    this creates you a matrix of 45 positions.

    2- When you create a matrix in this way var array=new Array(); you can create it empty so you can go putting all the objects you want or you can create it with a fixed length, but this last one is not recommended because when you use the method .length of the matrix will never be 0 and this can give many problems when using it.

    The other two questions I will not answer because I am not sure of its use and the last one could not answer it correctly since it depends on the practice of each user.

        
    answered by 20.04.2017 / 12:44
    source