Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What is difference between, number, any, object?

Some concepts are still under request, please help me?

// Why is there no error in this case?

fildAnyOne : any = [[],[]];
fildAnyTwo : any [] = [[],[]];
fildAnyThree: any [][] = [[],[]];

// Why is there no error in this case?

fildObjectOne: object = [[],[]];
fildObjectTwo: object [] = [[],[]];
fildObjectThree: object [][] = [[],[]];

// Why is there an error in this case?

fildNumberOneError : number = [[],[]];
fildNumberTwoError: number [] = [[],[]];
fildNumberThreeError: number [][] = [[],[]];

// Why is there no error in this case?

fildNumberOne : number = 1;
fildNumberTwo: number [] = [ 1, 2 ];
fildNumberThree: number [][] = [[1, 2], [3, 4]];

Why is this happening?

I know that number is an exact type.
But I don’t feel any change in object and any types, why?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

What is difference between number, any, any[], any [][] and object, object[], object[].

>Solution :

  // Why is there no error in this case?

  fildAnyOne : any = [
    [],
    []
  ];

Because any matches literally any type.

  // Why is there no error in this case?

  fildObjectOne: object = [
    [],
    []
  ];

Because arrays in JavaScript are objects too.

  // Why is there an error in this case?

  fildNumberOneError : number = [
    [],
    []
  ];

Because an array is obviously not a number.

  // Why is there no error in this case?

  fildNumberOne : number = 1;

Because 1 is a number.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading