JavaScript Interview Question #33: Add two empty arrays and check the type

Array? Object? Undefined? What’s the output?

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

In JavaScript, the + operator doesn’t do the concatenation of arrays.

Instead, it transforms them into strings and then does the string concatenation…


This content originally appeared on DEV Community and was authored by Coderslang: Become a Software Engineer

js-test-33

Array? Object? Undefined? What’s the output?

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

In JavaScript, the + operator doesn’t do the concatenation of arrays.

Instead, it transforms them into strings and then does the string concatenation.

Two empty arrays become two empty strings, and their sum unsurprisingly is still an empty string.

What matters to us is the typeof that will return string in our case.

ANSWER: the output will be string.

Learn Full-Stack JavaScript


This content originally appeared on DEV Community and was authored by Coderslang: Become a Software Engineer


Print Share Comment Cite Upload Translate Updates
APA

Coderslang: Become a Software Engineer | Sciencx (2021-04-16T12:09:00+00:00) JavaScript Interview Question #33: Add two empty arrays and check the type. Retrieved from https://www.scien.cx/2021/04/16/javascript-interview-question-33-add-two-empty-arrays-and-check-the-type/

MLA
" » JavaScript Interview Question #33: Add two empty arrays and check the type." Coderslang: Become a Software Engineer | Sciencx - Friday April 16, 2021, https://www.scien.cx/2021/04/16/javascript-interview-question-33-add-two-empty-arrays-and-check-the-type/
HARVARD
Coderslang: Become a Software Engineer | Sciencx Friday April 16, 2021 » JavaScript Interview Question #33: Add two empty arrays and check the type., viewed ,<https://www.scien.cx/2021/04/16/javascript-interview-question-33-add-two-empty-arrays-and-check-the-type/>
VANCOUVER
Coderslang: Become a Software Engineer | Sciencx - » JavaScript Interview Question #33: Add two empty arrays and check the type. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/04/16/javascript-interview-question-33-add-two-empty-arrays-and-check-the-type/
CHICAGO
" » JavaScript Interview Question #33: Add two empty arrays and check the type." Coderslang: Become a Software Engineer | Sciencx - Accessed . https://www.scien.cx/2021/04/16/javascript-interview-question-33-add-two-empty-arrays-and-check-the-type/
IEEE
" » JavaScript Interview Question #33: Add two empty arrays and check the type." Coderslang: Become a Software Engineer | Sciencx [Online]. Available: https://www.scien.cx/2021/04/16/javascript-interview-question-33-add-two-empty-arrays-and-check-the-type/. [Accessed: ]
rf:citation
» JavaScript Interview Question #33: Add two empty arrays and check the type | Coderslang: Become a Software Engineer | Sciencx | https://www.scien.cx/2021/04/16/javascript-interview-question-33-add-two-empty-arrays-and-check-the-type/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.