showing results for - "react native handle null safety"
Roosevelt
07 Jun 2016
1const adventurer = {
2  name: 'Alice',
3  cat: {
4    name: 'Dinah'
5  }
6};
7
8const dogName = adventurer.dog?.name;
9console.log(dogName);
10// expected output: undefined
11
12console.log(adventurer.someNonExistentMethod?.());
13// expected output: undefined
14
15Example:
16const value = undefinedCheck(appConfigurations?.language, 'EN');                                     
17console.log(value);
18                                     
19export function undefinedCheck(value, defaultValue) {
20  return (value !== undefined && value !== '' && value !== null) ? value : defaultValue;
21}
22
23