![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Why is [1,2] + [3,4] = “1,23,4” in JavaScript?
The JavaScript's + operator is used to add two numbers or join two strings. However, use the contact() method to join two arrays to get a new one. For example,
[50, 70].concat([90, 100])
The above prints,
[50, 70, 90, 100]
Let’s see your example. The + operator concats strings, and converts the arrays to strings −
[1,2] + [3,4] '1,2' + '3,4' 1,23,4
Or as mentioned above, use concat(),
[1,2].concat([3,4]) [1,2,3,4]
Advertisements