|
1 | | -# Hints |
2 | | - |
3 | | - |
4 | | -## 1. Check if a value is a boolean |
5 | | - |
6 | | -- You can use `typeof` to find the type of a value. |
7 | | -- `typeof` returns a string. |
8 | | - |
9 | | -## 2. Check if a value is a number. |
10 | | - |
11 | | -- You can use `typeof` to find the type of a value. |
12 | | -- `typeof` returns a string. |
13 | | -- You need to check for `Infinity` and `NaN`. |
14 | | -- `NaN` is never equal to itself, but there is a [built in function][isNaN] to check if a value is NaN. |
15 | | - |
16 | | -## 3. Check if a value is an object |
17 | | - |
18 | | -- You can use `typeof` to find the type of a value. |
19 | | -- `typeof` returns a string. |
20 | | -- You will need to check for `null`. |
21 | | - |
22 | | -## 4. Check if a string is numeric |
23 | | - |
24 | | -- You can use `typeof` to find the type of a value. |
25 | | -- `typeof` returns a string. |
26 | | -- You can iterate over a string to check if all characters are digits. |
27 | | - |
28 | | -## 5. Check if an object is electronic |
29 | | - |
30 | | -- You can use `instanceof` to check if an object is an instance of a class or one of its children. |
31 | | - |
32 | | -## 6. Check if a value is a non empty array |
33 | | - |
34 | | -- You can use `typeof` to find the type of a value. |
35 | | -- `typeof` returns a string. |
36 | | -- You can check the length of an array to find out how many elements it contains. |
37 | | - |
38 | | -## 7. Check if a value is an empty array |
39 | | - |
40 | | -- You can use `typeof` to find the type of a value. |
41 | | -- `typeof` returns a string. |
42 | | -- You can check the length of an array to find out how many elements it contains. |
43 | | - |
44 | | -## 8. Throw an error if an object does not have the `id` property |
45 | | - |
46 | | -- You can use the `in` operator or the `Object.hasOwn()` function to check if an object has a property. |
47 | | -- If the `id` property is missing, your function should throw an `Error`. |
48 | | - |
49 | | -## 9. Check if an object has a `type` property |
50 | | - |
51 | | -- You can use the `in` operator or the `Object.hasOwn()` function to check if an object has a property. |
52 | | - |
53 | | -## 10. Check if an object has a `constructor` property |
54 | | - |
55 | | -- All class instances have a `constructor`, but `Object.hasOwn()` is able to ignore this. |
56 | | - |
57 | | -## 11. Check if an object has a defined `type` property |
58 | | - |
59 | | -- You can use the `in` operator or the `Object.hasOwn()` function to check if an object has a property. |
60 | | -- You will have to access the `type` property and check if it is defined. |
61 | | - |
62 | | -[isNaN]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isNaN |
| 1 | +# Hints |
| 2 | + |
| 3 | + |
| 4 | +## 1. Check if a value is a boolean |
| 5 | + |
| 6 | +- You can use `typeof` to find the type of a value. |
| 7 | +- `typeof` returns a string. |
| 8 | + |
| 9 | +## 2. Check if a value is a number. |
| 10 | + |
| 11 | +- You can use `typeof` to find the type of a value. |
| 12 | +- `typeof` returns a string. |
| 13 | +- You need to check for `Infinity` and `NaN`. |
| 14 | +- `NaN` is never equal to itself, but there is a [built in function][isNaN] to check if a value is NaN. |
| 15 | + |
| 16 | +## 3. Check if a value is an object |
| 17 | + |
| 18 | +- You can use `typeof` to find the type of a value. |
| 19 | +- `typeof` returns a string. |
| 20 | +- You will need to check for `null`. |
| 21 | + |
| 22 | +## 4. Check if a string is numeric |
| 23 | + |
| 24 | +- You can use `typeof` to find the type of a value. |
| 25 | +- `typeof` returns a string. |
| 26 | +- You can iterate over a string to check if all characters are digits. |
| 27 | + |
| 28 | +## 5. Check if an object is electronic |
| 29 | + |
| 30 | +- You can use `instanceof` to check if an object is an instance of a class or one of its children. |
| 31 | + |
| 32 | +## 6. Check if a value is a non empty array |
| 33 | + |
| 34 | +- You can use `typeof` to find the type of a value. |
| 35 | +- `typeof` returns a string. |
| 36 | +- You can check the length of an array to find out how many elements it contains. |
| 37 | + |
| 38 | +## 7. Check if a value is an empty array |
| 39 | + |
| 40 | +- You can use `typeof` to find the type of a value. |
| 41 | +- `typeof` returns a string. |
| 42 | +- You can check the length of an array to find out how many elements it contains. |
| 43 | + |
| 44 | +## 8. Throw an error if an object does not have the `id` property |
| 45 | + |
| 46 | +- You can use the `in` operator or the `Object.hasOwn()` function to check if an object has a property. |
| 47 | +- If the `id` property is missing, your function should throw an `Error`. |
| 48 | + |
| 49 | +## 9. Check if an object has a `type` property |
| 50 | + |
| 51 | +- You can use the `in` operator or the `Object.hasOwn()` function to check if an object has a property. |
| 52 | + |
| 53 | +## 10. Check if an object has a `constructor` property |
| 54 | + |
| 55 | +- All class instances have a `constructor`, but `Object.hasOwn()` is able to ignore this. |
| 56 | + |
| 57 | +## 11. Check if an object has a defined `type` property |
| 58 | + |
| 59 | +- You can use the `in` operator or the `Object.hasOwn()` function to check if an object has a property. |
| 60 | +- You will have to access the `type` property and check if it is defined. |
| 61 | + |
| 62 | +[isNaN]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isNaN |
0 commit comments