Conditional Code in Jquery

by Vickram H 2012-09-04 01:05:33

Conditional Code in Jquery:

Sometimes you only want to run a block of code under certain conditions.
Flow control — via if and else blocks — lets you run code only under certain conditions.

Sample Code:

01 var foo = true;
02 var bar = false;
03
04 if (bar) {
05 // this code will never run
06 console.log('hello!');
07 }
08
09 if (bar) {
10 // this code won't run
11 } else {
12 if (foo) {
13 // this code will run
14 } else {
15 // this code would run if foo and bar were both false
16 }
17 }

581
like
0
dislike
0
mail
flag

You must LOGIN to add comments