[Vuejs]-Explanation for && usage when referring to google instance

0๐Ÿ‘

โœ…

&& is called a logical AND operator and in this case it is used to avoid errors. The MDN docs state that:

If expr1 can be converted to true, returns expr2; else, returns expr1.

This means that if variable google is not properly initialized it will return the falsy value instead of throwing an exception (e.g Cannot read property โ€˜mapsโ€™ of undefined/null).

Leave a comment