Welcome to the new installment of my series of Coding Quizzes, in which you will be able to test your knowledge and skills about programming and software development in a simple and fun way. If you want to learn more about it visit my blog here on Hive and the first post where I introduced it.
Solution to the previous quiz: undefined. Line 1 creates a new array a using the good, old function Array. Since two arguments were specified, the function will assume them as the elements of the array.
Line 2 also creates an array with the same special function, but by specifying a single numeric type argument, it understands it as the length of the array and will create it with undefined elements . As given in the code, we then have an array of three elements, but these are all undefined.
Line 3 applies the concat method to join the content of b with a, without modifying a , but creating a new array.
In the same line, a search is done with the find method where we want to obtain an item that is equal to 3. That item does not exist in the given array because, as we already saw, it could only be formed by the defined elements 1 and 2 and undefined elements, while the value 3 on line 2 is just a length, not an element.
The important thing to know is that when find does not get a match, what is returned is undefined, the most appropriate value that is opposed to a defined value, which is what was expected to be obtained.
This detail is important to know because although they are similar, undefined, null and false are different and our code may contain bugs if we do not appreciate these differences.
If you want to blog about computer science and programming content, I invite you to join Hive and participate in its communities, such as STEM-social, Develop Spanish, Programming & Dev, Hive Learners and others.
Bienvenido a mi nueva serie de Quizzes de Programaci贸n, en la cual podr谩s poner a prueba tus conocimientos y habilidades sobre programaci贸n y desarrollo de software de una manera sencilla y divertida. Si quieres aprender m谩s sobre ella visita mi blog aqu铆 en Hive y el primer post donde la present茅.
Soluci贸n al quiz anterior: undefined. La l铆nea 1 crea un nuevo arreglo a usando la vieja funci贸n Array. Como se especificaron dos argumentos, la funci贸n los asumir谩 como los elementos del arreglo.
La l铆nea 2 tambi茅n crea un arreglo con la misma funci贸n especial, pero al especific谩rsele un solo argumento de tipo num茅rico, esta lo entiende como la longitud del arreglo y lo crear谩 con elementos indefinidos. Como est谩 dado en el c贸digo, tenemos entonces un arreglo de tres elementos, pero estos son undefined todos.
La l铆nea 3 aplica el m茅todo concat para unir el contenido de b con a, sin modificar a, sino creando un nuevo arreglo.
En la misma l铆nea se hace una b煤squeda con el m茅todo find donde queremos obtener un item que sea igual a 3. Ese 铆tem no existe en el arreglo dado porque, como ya vimos, solo podr铆a estar formado por los elementos definidos 1 y 2 y elementos indefinidos, mientras que el 3 de la l铆nea 2 es solo una longitud, no un elemento.
Lo importante es saber que cuando find no obtiene una coincidencia, lo que regresa es undefined, el valor m谩s apropiado que se contrapone a un valor definido, que es lo que se esperaba obtener.
Este detalle es importante saberlo porque aunque son similares, undefined, null y false son distintos y nuestro c贸digo puede contener bugs si no apreciamos esas diferencias.
Si quieres bloguear sobre contenido inform谩tico y de programaci贸n, te invito a unirte a Hive y participar en sus comunidades, tales como STEM-social, Develop Spanish, Programming & Dev, Hive Learners y otras.