I saw this example and wondered why anyone would do it:
function a(str) {
return [
'<div>',
str,
'</div>'
].join('');
}
Isn't it an equivalent to the following code and what's the advantages / disadvantages of using just:
function a(str) {
return '<div>' +
str +
'</div>;
}
Thank you.
They're the same thing. Some experiments have shown using the + operator is faster but this will vary between browsers. Not to mention, these kinds of micro-optimizations don't tend to contribute much.
So which one is better? Whichever one you like the most.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With