Default value in TypeScript class

Today I have a very strange error filedN: Cast to Number failed for value "NaN" (type number) at path "filedN" when I am converting a Springboot REST service to Node.js service. As said in Why Serverless, I am using NestJS framework with TypeScript to write the REST service, while using Mongoose as the MongoDB object modeling tool.

As all Java developers know, you don't need to initialize instance variables because they always have a default value.

Data Type Default Value
byte 0
short int
long 0L
float 0.0f
double 0.0d
char
String (or any object) null
boolean false

Without thinking too much, my converted TypeScript class looks like

			@Schema()
			export class ABCDClass {
			    ...
			    @Prop() fieldN : number; 
			    ...
			}
		

When I instantiate an ABCDClass object by calling new ABCDClass(), the closeNAV field is set to "NaN" in Node.js runtime. In my calculation I calculate all other fields and set proper numbers to them but not fieldN, then I get this error when I try to save it to MongoDB through Mongoose.

It is a pretty easy fix by setting the default value 0 to filedN in the class definition.

            @Schema()
            export class ABCDClass {
                ...
                @Prop() fieldN : number = 0; 
                ...
            }
        
It is just very interesting to notice this difference between Java and TypeScript/Javascript. Looks like I have some work tonight to go through all my TypeScript classes and set the default value to the instance variables with number and boolean types.