|
| 1 | +/* |
| 2 | +
|
| 3 | +1. |
| 4 | +
|
| 5 | +
|
| 6 | +console.log('a'-1)//nan |
| 7 | +console.log('tilak'+100) |
| 8 | +
|
| 9 | +console.log(+false)//0 |
| 10 | +console.log(+true)//1 |
| 11 | +console.log(+null)//0 |
| 12 | +console.log(+undefined)//NaN |
| 13 | +console.log(!"Nilaj")//false |
| 14 | +
|
| 15 | +console.log(null == undefined); // true because both are equal in value null is equal to undefined |
| 16 | +console.log(null === undefined); // false because both are not equal in type undefind type is undefined and null type is object. |
| 17 | +
|
| 18 | +console.log(NaN == NaN); // false because nan is false in value and type is number |
| 19 | +console.log(NaN === NaN);//false |
| 20 | +
|
| 21 | +console.log(typeof(NaN))//number |
| 22 | +console.log(NaN)NAN |
| 23 | +console.log(NaN==4) //false |
| 24 | +console.log(NaN=="4")//falsy |
| 25 | +console.log(NaN!=4)//true |
| 26 | +console.log(NaN==true)// false |
| 27 | +console.log(NaN==false) //false |
| 28 | +
|
| 29 | +
|
| 30 | +2. |
| 31 | +const a = {} |
| 32 | +const b = { |
| 33 | + name: 'tilak' |
| 34 | +} |
| 35 | +const c = { |
| 36 | + name: 'ram' |
| 37 | +} |
| 38 | +a[b] = { |
| 39 | + name: 'ankit' |
| 40 | +} |
| 41 | +a[c] = { |
| 42 | + name: 'rahul' |
| 43 | +} |
| 44 | +
|
| 45 | +console.log(a[b]);//rahul |
| 46 | +
|
| 47 | +
|
| 48 | +
|
| 49 | +3. |
| 50 | +let arr = [5, 3, 8, 1, 2]; |
| 51 | +
|
| 52 | +// Sort the array using a callback function |
| 53 | +arr.sort((a, b) => a - b); // Ascending order |
| 54 | +
|
| 55 | +console.log(arr); // Output: [1, 2, 3, 5, 8] |
| 56 | +
|
| 57 | +
|
| 58 | +
|
| 59 | +
|
| 60 | +4. function infiniteCurry(val1){ |
| 61 | + return function(val2){ |
| 62 | + if(!val2){ |
| 63 | + return val1; |
| 64 | + } |
| 65 | + return infiniteCurry(val1 + val2) |
| 66 | + } |
| 67 | +} |
| 68 | +
|
| 69 | +console.log(infiniteCurry(1)(2)(3)()) |
| 70 | +
|
| 71 | +
|
| 72 | +
|
| 73 | +5. //Array destructuring |
| 74 | +let arr = [1, 2, 3]; |
| 75 | +
|
| 76 | +// Destructuring the array into variables |
| 77 | +let [a, b, c] = arr; |
| 78 | +
|
| 79 | +console.log(a); // Output: 1 |
| 80 | +console.log(b); // Output: 2 |
| 81 | +console.log(c); // Output: 3 |
| 82 | +
|
| 83 | +*/ |
| 84 | + |
| 85 | + |
| 86 | + |
| 87 | + |
| 88 | + |
0 commit comments