Unexpected string concatenation
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
In ES2015 (ES6), we can use template literals instead of string concatenation.
var str = `Hello, ${name}!`;
Bad Practice
var str = "Hello, " + name + "!";
var str = "Time: " + (12 * 60 * 60 * 1000);
Recommended
var str = "Hello World!";
var str = `Hello, ${name}!`;
var str = `Time: ${12 * 60 * 60 * 1000}`;
var str = "Hello, " + "World!";