Page 1 of 1

Return value documentation errors

Posted: 02 Jul 2019, 08:14
by Rob
There are several places in the documentation where functions are listed as returning null, when they in fact return undefined.
This will obviously cause bugs if a developer explicitly checks for null.

Examples are the getUserById & getUserByName functions.

Re: Return value documentation errors

Posted: 02 Jul 2019, 09:16
by Lapo
Hi,
I am not clear on the use case. What do you mean by "if a developer explicitly checks for null"?
Using the tripe equals operator (===) ?

Thanks

Re: Return value documentation errors

Posted: 02 Jul 2019, 13:19
by Rob
While both null and undefined are falsy values in Javascript they are not the same. So if the developer assumes null is what indicates an error, something like this could happen:

Code: Select all

const usr = myRoom.getUserById(x);
if (usr === null) {
	// Handle error
} else {
	// Assume all is OK
}

Re: Return value documentation errors

Posted: 02 Jul 2019, 15:45
by Lapo
Sure, because null and undefined represent different states they don't "mean" the same thing, though in practical terms they do, most of the times.

We'll certainly fix that in the docs.
At the same time, since we're nitpicking, I am not sure why you would need to use the === operator (in that context) to check for a null value, where there is no ambiguity implied or declared.

I would expect the === to be useful where you need to distinguish between null and undefined. In those cases there is no such need. You either get an object, or you don't.

Regardless, thanks for reporting.

Re: Return value documentation errors

Posted: 02 Jul 2019, 16:15
by Rob
Yeah, I wouldn't use === like that. I would use something like if (!usr) { ... } it was just an example of what might happen with the current documentation.

Re: Return value documentation errors

Posted: 03 Jul 2019, 09:35
by Bax
We fixed the documentation issues. Again, thank you for reporting.