Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modify tip to avoid throwing; closes #42 #279

Merged
merged 1 commit into from
Mar 1, 2016

Conversation

boneskull
Copy link
Contributor

Modified tip and a bit of explanation to avoid throwing a TypeError. As written, it can throw an exception if called without a parameter:

> function printUpperCase(words) {
  var elements = [].concat(words);
   for (var i = 0; i < elements.length; i++) {
     console.log(elements[i].toUpperCase());
   }
 }
> printUpperCase()
TypeError:  Cannot read property 'toUpperCase' of undefined

Note that this does not avoid the exception thrown when words is neither a string nor an Array of strings.

@loverajoel
Copy link
Owner

@boneskull nice catch!

@Mattfxyz can you take a look here?

@zenopopovici
Copy link
Collaborator

Not sure how safe || [] is ... but in this case ...

@mattfaluotico
Copy link
Contributor

This was mostly a theoretical example. It's not really code you would ever really use in production because it's such silly function. You can merge it, but I think it takes away from what the example is about.

@kurtextrem
Copy link
Contributor

It makes the tip more complete. However, I would refrain from explaining that little part. A separate tip would be better I'd say (quick, but useful!)
(Example title "Logical Operators don't only compare" or so - probably something for me? :D)

zenopopovici added a commit that referenced this pull request Mar 1, 2016
Modify tip to avoid throwing; closes #42
@zenopopovici zenopopovici merged commit 5e953b1 into loverajoel:gh-pages Mar 1, 2016
@zenopopovici
Copy link
Collaborator

I've merged it. Thanks!

@boneskull
Copy link
Contributor Author

ty

@boneskull boneskull deleted the issue/42 branch March 1, 2016 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants