concat variable and string javascript code example

Example 1: javascript concat

let chocholates = ['Mars', 'BarOne', 'Tex'];
let chips = ['Doritos', 'Lays', 'Simba'];
let sweets = ['JellyTots'];

let snacks = [];
snacks.concat(chocholates);
// snacks will now be ['Mars', 'BarOne', 'Tex']
// Similarly if we left the snacks array empty and used the following
snacks.concat(chocolates, chips, sweets);
//This would return the snacks array with all other arrays combined together
// ['Mars', 'BarOne', 'Tex', 'Doritos', 'Lays', 'Simba', 'JellyTots']

Example 2: how to concatenate strings and variables in javascript

const helloName = name => `Hello ${name}!`

Example 3: concantene number in js

Use "" + 5 + 6 to force it to strings. 
This works with numerical variables too:

var a = 5;
var b = 6;
console.log("" + a + b);

Example 4: js concat variable and string

const txt = "My name is"
console.log(`${txt} Paul`);