Skip to content

Conversation

Vemus
Copy link

@Vemus Vemus commented Oct 22, 2016

Chapter 4: Data Structures: Objects and Arrays; Code Sandbox: 1: The Sum of a Range; Line 2.

@marijnh
Copy link
Owner

marijnh commented Oct 22, 2016

In JavaScript, x == null and x == undefined do the exact same thing.

@marijnh marijnh closed this Oct 22, 2016
@Vemus
Copy link
Author

Vemus commented Oct 23, 2016

If x === null for this problem, it doesn't accept a missing parameter for step and an empty array is returned. It only works if x === undefined.

@fxfactorial
Copy link

@marijnh I would say that for this code sample undefined is more expressive of the code's intention. Parameters which are not explicitly passed get a value of undefined, whereas the null would have required caller to explicitly give it as null. Given that the step is the trailing argument and step is usually optional, I would rather the code check for undefined rather than null, as is common in JavaScript coding conventions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants