My Coding Quiz #33

avatar
(Edited)

My Coding Quiz #33 👨‍💻🛠️🧩

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.

Without further ado, here's the riddle...




Quiz
By @eniolw


What's your choice?

Solution to the previous quiz: number. Line 1 creates a string that can be easily interpreted as a date.

Then we create three variables using the powerful destructuring assignment feature of JavaScript with which we assign to several variables the contents of an array or object, in this case the array created by the split method. The variables m, d and y have the values '11', '30', '2023' respectively.

We then initiate a series of nested try-catch clauses. One more level of nesting would make programmers like Linus Torvalds insult you, ha ha. Let's examine them more closely.

console.log(typeof Float(y)) cannot be executed because the Float function or class does not exist in JavaScript in this form. Did you know that?

console.log(typeof(+y)) does run because it is valid code. The parentheses for the typeof operator are unnecessary here, but they are not a syntax error. The key is that the + operator placed in front of a variable like this will force or attempt a type conversion if the type of the variable is not numeric already. As a consequence, the value of y will be converted to number type and we will get that as output.

console.log(typeof(y)) would not be able to be executed in this script, but it is valid code as well.

The crux of this quiz, therefore, is to know the potential of the unary operator + to do these data type conversions. It is difficult to consider it a hack, since it is in fact the method recommended by MDN and other specialized sites, which consider it the "fastest" and the "preferred" one, which in turn makes ParseInt and other similar conversion methods obsolete.


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 and others.


Mi Quiz de Programación #33 👨‍💻🛠️🧩

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é.

Sin más preámbulos, he aquí el acertijo...




Quiz
Por @eniolw


¿Cuál es tu elección?

Solución al quiz anterior: number. La línea 1 crea una cadena que puede interpretarse fácilmente como una fecha.

Luego creamos tres variables usando la potente funcionalidad de asignación destructuring de JavaScript con la que asignamos a varias variables el contenido de un array u objeto, en este caso el array creado por el split método. Las variables m, d y y tienen los valores '11', '30', '2023' respectivamente.

Luego iniciamos una serie de cláusulas try-catch anidadas. Un nivel más de anidamiento haría que programadores como Linus Torvalds te insultaran, ja, ja. Examinémoslos más de cerca.

console.log(typeof Float(y)) no se puede ejecutar porque la función o clase Float no existe en JavaScript de esta manera. ¿Lo sabías?

console.log(typeof(+y)) se ejecuta porque es un código válido. Los paréntesis para el operador typeof son innecesarios aquí, pero no constituyen un error de sintaxis. La clave es que el operador + colocado delante de una variable así forzará o intentará una conversión de tipo si el tipo de la variable aún no es numérico. Como consecuencia, el valor de y se convertirá a un tipo numérico y lo obtendremos como resultado.

console.log(typeof(y)) no podría ejecutarse en este script, pero también es un código válido.

El meollo de este quiz, por lo tanto, es conocer el potencial del operador unario + para realizar estas conversiones de tipos de datos. Es difícil considerarlo un hack, ya que es en realidad el método recomendado por MDN y otros sitios especializados, que lo consideran el "más rápido" y el "preferido", lo que a su vez hace que ParseInt y otros métodos de conversión similares queden obsoletos.


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 y otras.



0
0
0.000
6 comments
avatar

Oh wow this is pretty crazy! Absolute wild and crazy as well..

However I am actually very impressed. And I think that coding as well as coding boot camps and teaching other people this arcane mysterious art would be more prevalent here on the blockchain...

I do a secrets of Hive class and I'd totally trade you for some beginning coding knowledge. I think that your coding content actually I might be more important than you understand..

Nobody here really explains it. We've got a lot of really great coders here that talk in Klingon!

Thank you very much for your excellent post. As well as thank you for sharing the knowledge of coding.

#freecompliments

0
0
0.000
avatar

Thanks for your contribution to the STEMsocial community. Feel free to join us on discord to get to know the rest of us!

Please consider delegating to the @stemsocial account (85% of the curation rewards are returned).

You may also include @stemsocial as a beneficiary of the rewards of this post to get a stronger support. 
 

0
0
0.000