
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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]
- Related Questions & Answers
- Why avoid increment (“++”) and decrement (“--”) operators in JavaScript?
- Why does the JavaScript need to start with “;”?
- Python Object Comparison “is” vs “==”
- Why in JavaScript, “if ('0' == false)” is equal to false whereas it gives true in “if(0)” statement?
- What is an exclamation “!” operator in JavaScript?
- Why is “LIMIT 0” even allowed in MySQL SELECT statements?
- Why “using namespace std” is considered bad practice in C++
- Why is using “for…in” loop in JavaScript array iteration a bad idea?
- Why is using “for…in” with array iteration a bad idea in javascript?
- Explain import “as” and Export “as” constructs in JavaScript.
- Is there a “null coalescing” operator in JavaScript?
- Which one is better to use for a JavaScript link, “#” or “javascript:void(0)”?
- Why does Lua have no “continue” statement?
- MySQL “order by” inside of “group by”? Is it possible?
- How to create a dialog with “yes” and “no” options in JavaScript?
Advertisements