Grateful Grateful - 1 month ago 4
AngularJS Question

Why `auth.logout && auth.logout();` in the following example?

I am looking at the angular authentication application at https://codepen.io/aronrodrigues/pen/YXvBWW. But I don't understand what is happening with the statement

auth.logout && auth.logout();
on line 102 of the js file. Why does it appear to be calling
auth.logout
twice?

Any hints?

Answer

I'm not familiar with Angular, but in JavaScript the first auth.logout doesn't actually call the function. It will return the function itself, making sure that the function only gets called (the second auth.logout()) if it actually exists.