Issue
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?
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
.
Answered By - Thomas
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.