• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

confused by javascript/angular code operator ||

 
Ranch Hand
Posts: 42
2
Mac Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 42
2
Mac Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tested the following code in in JSFiddle, and it returned 0.  Why is this not returning false?

 
reply
    Bookmark Topic Watch Topic
  • New Topic