use
String(str.charCodeAt(i).toString(16))
instead 34 function convertToHex(str: string) {
35 var hex = "";
36 for (var i = 0; i < str.length; i++) {
37 hex += "" + str.charCodeAt(i).toString(16); 38 }
39 return hex;
40 }
Description
Prefer using explicit casts by calling Number
, Boolean
, or String
over using operators like +
, !!
or "" +
.
This is considered best practice as it improves readability.
Bad Practice
const b = !!foo;
// The `+` operator does not change the value of its operand
// unless it's already a number.
let n = +foo;
n = 1 * foo;
const s = "" + foo;
Recommended
const b = Boolean(foo);
const n = Number(foo);
const s = String(foo);