+'11111'
results in the number 11111
because unary + converts the expression on its right side to a number. But there's no such thing as "unary *", so *'11111'
throws an error. (What would *'11111'
even mean?)
As for the IIFEs:
;(function() {
})()
the ;
ensures that the IIFE starts after the end of the previous statement. Were it not for the ;
, and the previous statement did not end with a ;
, the lack of Automatic Semicolon Insertion on the previous line could cause bugs:
const arr = []
(function() {
})()
But using +
without a semicolon on the previous line is not a good idea, because then the return value of the IIFE can be added or concatenated to the previous line:
const arr = []
+(function() {
})()
console.log(arr);
If you always put semicolons at the end of statements when appropriate, then there's no need to put anything before the (
of an IIFE:
const arr = [];
(function() {
console.log('iife');
})();
console.log(arr);
(If you aren't an expert, I'd recommend using semicolons, rather than relying on the slightly strange rules of ASI - they'll sometimes result in hard-to-understand bugs)