-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2_concat_coercion.js
33 lines (28 loc) · 1.52 KB
/
2_concat_coercion.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//* ============================
//* Data Types Section - part 2
//* ============================
//* Concatenation in JavaScript
//? In JavaScript, the + sign is not only used for arithmetic addition but also for string concatenation. When the + operator is used with strings, it concatenates the strings together.
//? It's important to note that if any operand of the + operator is a string, JavaScript will treat the other operands as strings as well, resulting in string concatenation. If both operands are numbers, the + operator performs numeric addition.
// const str = "Hello " + "World";
// console.log(str);
//* Type coercion is the automatic conversion of "values" from one data type to another.
//? It is a fundamental part of JavaScript and can be used to make code more readable and efficient.
//? There are two types of coercion in JavaScript: implicit and explicit. Implicit coercion happens automatically, while explicit coercion is done manually by the programmer.
//! It's worth noting that type coercion can lead to unexpected results, so it's essential to be aware of how JavaScript handles these situations.
// let sum = "5" + 10;
// console.log(sum);
//* ============================
//* Tricky Interview Questions
//* ============================
console.log(10 + "20");
console.log(9 - "5");
console.log("Java" + "Script");
console.log(" " + " ");
let sum = " " + 0;
console.log(typeof sum);
console.log("vinod" - "thapa");
console.log(true + true);
console.log(true + false);
console.log(false + true);
console.log(false - true);