-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path+_operator.js
More file actions
14 lines (11 loc) · 867 Bytes
/
+_operator.js
File metadata and controls
14 lines (11 loc) · 867 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//Using the + operators on strings and numbers
//Combining two strings using the + operator
//If the + operator is used to join strings, then it is referred to as the concatenation operator, and you'll say that it's used to concatenate strings.
console.log("inter"+"net");
console.log("note"+"book");
//Combining strings and numbers using the + operator
console.log(360+" days");
console.log(12+" months");//Here, JavaScript tries to help by converting the numbers to strings, and then concatenating the number and the string together, ending up with a string value.
//The process of this "under-the-hood" conversion of values in JavaScript is referred to as "coercion". JavaScript coerces a number value to a string value - so that it can run the + operator on disparate data types.
//The process of coercion can sometimes be a bit unexpected.
console.log(1+"2");