Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #28659
| From | Tim Streater <timstreater@greenbee.net> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: explode a string function gets an undefined result |
| Date | 2015-09-07 15:58 +0100 |
| Message-ID | <070920151558455577%timstreater@greenbee.net> (permalink) |
| References | <f938f9dd-e322-4370-bc80-379ea36b83aa@googlegroups.com> <msjvp4$vde$1@news.albasani.net> |
In article <msjvp4$vde$1@news.albasani.net>, Stefan Weiss
<krewecherl@gmail.com> wrote:
>On 2015-09-07 03:03, JRough wrote:
>> var str = 'janis';
>> var myfunc = function explode(str){
>> for (var i=0, out; i< str.length; i++){
>> out = out + " " + str.charAt(i);
>>
>> }
>> alert(out);
>> }
>> output = myfunc(str);
>>
>>
>> why is the result "undefined j a n i s???, thanks
>
>See Tim Streater's answer: `out` is declared but not defined.
>undefined + " " -> "undefined "
>
>I couldn't help noticing two other things (apart from the unconventional
>indentation):
>
>1) Do you want to address your function as myfunc() or explode()?
>
>2) Consider "janis".split("").join(" ")
I thought there were probably better answers than mine. :-)
--
"If you're not able to ask questions and deal with the answers without feeling
that someone has called your intelligence or competence into question, don't
ask questions on Usenet where the answers won't be carefully tailored to avoid
tripping your hair-trigger insecurities." - D M Procida, UCSM
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
explode a string function gets an undefined result JRough <janis.rough@gmail.com> - 2015-09-06 18:03 -0700
Re: explode a string function gets an undefined result Tim Streater <timstreater@greenbee.net> - 2015-09-07 09:37 +0100
Re: explode a string function gets an undefined result Stefan Weiss <krewecherl@gmail.com> - 2015-09-07 14:26 +0200
Re: explode a string function gets an undefined result Tim Streater <timstreater@greenbee.net> - 2015-09-07 15:58 +0100
Re: explode a string function gets an undefined result JRough <janis.rough@gmail.com> - 2015-09-08 14:29 -0700
Re: explode a string function gets an undefined result "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-09-09 00:01 +0200
Re: explode a string function gets an undefined result Stefan Weiss <krewecherl@gmail.com> - 2015-09-09 00:50 +0200
Re: explode a string function gets an undefined result "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-09-09 09:19 +0200
Re: explode a string function gets an undefined result JRough <janis.rough@gmail.com> - 2015-09-09 10:30 -0700
Re: explode a string function gets an undefined result Tim Streater <timstreater@greenbee.net> - 2015-09-09 22:15 +0100
csiph-web