Win a 3 month subscription to Marco Behler Videos this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

confused by javascript/angular code operator ||  RSS feed

 
Brian Jones Jr.
Ranch Hand
Posts: 39
2
Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to work through the AngularJS v1.2 tutorial. The task is to:

Add a method to GalleryController called setCurrent that accepts a value and assigns it to current. If no value is passed in, set current to 0.

The pertinent code in app.js



Here's the index.html that uses that GalleryController



I don't understand how || works on line 8. According to the MDN docs for Logical Operators I think this should set this.current to false if nothing is passed into it. I am confused. Can someone help me? Thanks.
 
Brian Jones Jr.
Ranch Hand
Posts: 39
2
Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tested the following code in in JSFiddle, and it returned 0.  Why is this not returning false?

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!