Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
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
