Wednesday, June 5, 2024
 Popular · Latest · Hot · Upcoming
133
rated 0 times [  135] [ 2]  / answers: 1 / hits: 15533  / 5 Years ago, sat, june 1, 2019, 12:00:00

I need to create an object with some non-defined values.
I know how to declare an empty string- in example that would be a object.name. But what would be an empty numeric value. What do I need to put instead of word 'number' in object.age property to tell the javaScript it can be any number?


let object = {
name : ''
age : number
}

More From » javascript

 Answers
2

You could take NaN, not a number as value, this values has a number type and not a usefull value.



let object = {
name : '',
age : NaN
};


If you not like to use NaN, you might use null or just undefined, but the first one is an object and the second is undefined as type.



And for checking if value equals to these defines:



NaN: isNaN(object.age)
null: object.age===null
undefined: typeof object.age===undefined

[#52051] Friday, May 24, 2019, 5 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jack

Total Points: 557
Total Questions: 96
Total Answers: 80

Location: Saint Helena
Member since Mon, Jan 16, 2023
1 Year ago
jack questions
Sun, Jan 31, 21, 00:00, 3 Years ago
Thu, Dec 10, 20, 00:00, 4 Years ago
Sat, Aug 1, 20, 00:00, 4 Years ago
Fri, Apr 17, 20, 00:00, 4 Years ago
Wed, Aug 14, 19, 00:00, 5 Years ago
;