filmov
tv
JavaScript Tips — The optional chaining call operator

Показать описание
The optional chaining call operator lets you safely call a function or method that may be null or undefined. You write it with ?. before the parentheses of a function call, for example:
myFunc?.(arg1, arg2, ...)
Here The function call is only made if the value on the lefthand side (myFunc) is not null or undefined. If the lefthand side value is null or undefined, the function call is skipped and the entire expression evaluates to null or undefined.
This is more concise than using an if-statement or ternary operator for this
#javascript
myFunc?.(arg1, arg2, ...)
Here The function call is only made if the value on the lefthand side (myFunc) is not null or undefined. If the lefthand side value is null or undefined, the function call is skipped and the entire expression evaluates to null or undefined.
This is more concise than using an if-statement or ternary operator for this
#javascript