Reputation: 161
Please, help me, guys
var main_html = String()
+ '<div class="spa-shell-head">'
+ '<div class="spa-shell-head-logo"></div>'
+ '</div>'
same thing:
var main_html = '<div class="spa-shell-head">'
+ '<div class="spa-shell-head-logo"></div>'
+ '</div>'
what is the difference?
p.s. Sorry for my english. Thank you
Upvotes: 0
Views: 54
Reputation: 1108
first of all it looks like you just need to use equal sign instead of colon.
var main_html = String()
+ '<div class="spa-shell-head">'
+ '<div class="spa-shell-head-logo"></div>'
+ '</div>';
Putting String()
(or just empty string like ''
) in the beginning of an addition expression will give us resulting string. Sort of type coercion in JS.
E.g.
String() + 5 --> '5'
,
String() + true --> 'true'
, etc.
With it you can be sure that main_html
variable is string, not number or boolean.
Actually in your case it is not obligatory to write it in that way. Since you're adding string to string you'll always get string. So the second code example works completely the same as the first one.
Upvotes: 1