number
s or string
s in addition expressions JS-0377+
operator should be both numbers or both strings26 const newUser = getUser(username);
27 setUser(newUser);
28 setLocalUser(newUser);
29 toast.success(newUser?.fullName + " has logged in successfully!");30
31 if (newUser) {
32 dispatch(
+
operator should be both numbers or both strings 1export const createDate = (value: Date) => {
2 const currentDate = value;
3 const date =
4 currentDate.getFullYear() + 5 "-" + 6 (currentDate.getMonth() + 1) +
7 "-" +
8 currentDate.getDate();
+
operator should be both numbers or both strings 7 "-" +
8 currentDate.getDate();
9 const time =
10 currentDate.getHours() +11 ":" +12 currentDate.getMinutes() +
13 ":" +
14 currentDate.getSeconds();
+
operator should be both numbers or both strings 7 "-" +
8 currentDate.getDate();
9 const time =
10 currentDate.getHours() +11 ":" +12 currentDate.getMinutes() +13 ":" +
14 currentDate.getSeconds();
15 const dateTime = date + " " + time;
+
operator should be both numbers or both strings 7 "-" +
8 currentDate.getDate();
9 const time =
10 currentDate.getHours() +11 ":" +12 currentDate.getMinutes() +13 ":" +14 currentDate.getSeconds();15 const dateTime = date + " " + time;
16 return dateTime;
17};
It is recommended to use operands of the same type while adding values as mismatched operand types might result in unexpected output.
When doing addition with operands of different types, the output sometimes results in simple concatenation instead of addition.
1 + '2'
While the user may expect this to result in 3
(by integer addition) it will instead result in '12'
(by string concatenation) .
var foo = '5.5' + 5;
var foo = 1n + 1;
var foo = parseInt('5.5', 10) + 10;
var foo = 1n + 1n;