saner
saner

Reputation: 821

Int entered verificatiion - Parse Server Cloud Code

I use the new Parse Server, and in the cloud part which is using Javascript I want to check if an integer is specified by a user, in other words I want to check if the Int is null or not. I can do it for strings, but as I see from comments, an int can not be null. Bu I do not want to change all ints in my code to integers. I try the code below, but it is not working, how can I check if there is a number specified by the user or if it is empty?

 if (!req.object.get('number'))

Upvotes: 0

Views: 56

Answers (1)

Simon Bengtsson
Simon Bengtsson

Reputation: 8151

Your code should work as long as number isn't zero. To handle that case as well, simply do a type check like this:

if (typeof req.object.get('number') !== 'number').

It seems like you are confusing java and javascript. Javascript does not have ints or integers, only numbers. Javascript variables do not have types and all variables can be null and undefined.

Upvotes: 1

Related Questions