Beginning AngularJS

(WallPaper) #1
ChApter 1 ■ JAvASCrIpt You Need to KNow

Listing 1-25. Nested Conditional Logic


<!DOCTYPE html>




JavaScript Primer





This listing is similar to Listing 1-23, the difference being that there is no else counterpart to the if statement. In
these cases, when the condition evaluates to false, no action is taken at all. Also, we use a nested if/else statement.
So, if the user is logged in, we ask yet another question: is this user a VIP member? As userIsVIP evaluates to true, we
give this member a much higher discount.


Welcome back - showing you to some very private data
You are entitled to a 25% discount!


Working with Arrays

JavaScript arrays are used to store multiple values in a single variable. JavaScript arrays are quite flexible in that you
can store variables of different types within them. (Some languages do not allow for this.) Arrays allow you to work,
based on the position of contained items, by using a numeric index. Listing 1-26 is a basic example of creating an
array and adding values to it.

Free download pdf