jrough
9/9/2015 5:30:00 PM
On Tuesday, September 8, 2015 at 3:50:49 PM UTC-7, Stefan Weiss wrote:
> On 2015-09-09 00:01, Evertjan. wrote:
> > JRough <janis.rough@gmail.com> wrote on 08 Sep 2015 in comp.lang.javascript:
> >> var str = 'janis';
> >> function explode(str) {
> >> use 'strict';
> >
> > 'use strict';
>
> Exactly. I have to admit, I've made variations of this error myself a
> few times... old Perl habits die hard :)
>
> > However, why do you need 'use strict'
>
> To make JSLint happy, I suppose. Using a lint checker before posting is
> commendable, but I would personally recommend JSHint over JSLint (for
> various reasons; the margin of this message is too narrow to contain
> them all). Both linters have on/off settings for strict mode.
>
> Janis: This script will have the same problem as before, even when the
> syntax error is resolved. `out` is still undefined the first time you
> add " " to it, resulting in "undefined " again. To solve this, you need
> to initialize `out` to an empty string.
>
> var i, out = "";
> for (i = 0; i < mystr.length; i++) {
> ...
>
> When this works, the result should be " j a n i s". Note the leading
> space. If you don't want that, your function could return out.trim() or
> out.substring(1) or out.slice(1).
>
>
> - stefan
thanks,