javascript comments and conditionals
DESCRIPTION
This is the slide stack to accompany the YouTube video of the same name at http://youtu.be/OKbh3SMUALcTRANSCRIPT
![Page 1: JavaScript Comments and Conditionals](https://reader036.vdocuments.net/reader036/viewer/2022081414/54b7abcd4a79594b258b468a/html5/thumbnails/1.jpg)
JavaScript Comments and Conditionals
Charles Russell
Bennu Bird Media
![Page 2: JavaScript Comments and Conditionals](https://reader036.vdocuments.net/reader036/viewer/2022081414/54b7abcd4a79594b258b468a/html5/thumbnails/2.jpg)
Note Taking
● Detectives journal● Fire Log● Sketch books
● In programs we use comments
![Page 3: JavaScript Comments and Conditionals](https://reader036.vdocuments.net/reader036/viewer/2022081414/54b7abcd4a79594b258b468a/html5/thumbnails/3.jpg)
Comments are for people not machines
● Notes to others and ourselves describing our thinking.
● Often used to outline the program with pseudo code.
● Establish proprietary information like authorship copyright and other
● Documentation
![Page 4: JavaScript Comments and Conditionals](https://reader036.vdocuments.net/reader036/viewer/2022081414/54b7abcd4a79594b258b468a/html5/thumbnails/4.jpg)
Comments in JavaScript
● Single line comment //● From where the comment begins to end of line
● Multi-line comment /* */● Begins with /* and continues to be ignored no matter
how many lines until */● Documentation comment /** */
● Used by documentation tools like Scriptdoc or Doxygen to document code in the code document and extract to either a sepeate document of web page.
![Page 5: JavaScript Comments and Conditionals](https://reader036.vdocuments.net/reader036/viewer/2022081414/54b7abcd4a79594b258b468a/html5/thumbnails/5.jpg)
Branching out
● It is very common to want to decide one of two paths for a program to take● Statements that choose between multiple courses of action are called conditional
statemens● If statements provide that branch
● if (condition ) doSomething() else doSomethingElse()
if (boolean) {
statement1;
statement2;
}else{
// This code block executes if falsey
…
}
![Page 6: JavaScript Comments and Conditionals](https://reader036.vdocuments.net/reader036/viewer/2022081414/54b7abcd4a79594b258b468a/html5/thumbnails/6.jpg)
Multibranch Selection
● If great for when you have only two possible paths● What if you have many paths
● else if to the rescue
if (condition) {
doSomething
} else if ( condition) {
doAnotherThing
} else{
doSomethingElse
![Page 7: JavaScript Comments and Conditionals](https://reader036.vdocuments.net/reader036/viewer/2022081414/54b7abcd4a79594b258b468a/html5/thumbnails/7.jpg)
Switch JavaScript's Manifold
● Switch is another way to branch into one of many paths● Two other keywords needed for this statement
– case: this is the conditional– break Breaks out of the switch
● Optional default keyword– This part of the switch is executed if no other condition is
met
![Page 8: JavaScript Comments and Conditionals](https://reader036.vdocuments.net/reader036/viewer/2022081414/54b7abcd4a79594b258b468a/html5/thumbnails/8.jpg)
Switch the syntax
switch (a) {
case value:
statements
break;
case value2:
statements
break;
default:
statements
}
![Page 9: JavaScript Comments and Conditionals](https://reader036.vdocuments.net/reader036/viewer/2022081414/54b7abcd4a79594b258b468a/html5/thumbnails/9.jpg)
Summary
● Comments allow to keep notes and document your code● There are single line and multiline comment types
● A special multiline comment can aid in documentation● Conditional statements allow branching to alter operational
flow.● { } define code blocks (and somethings we will get to soon)● If ( conditional expression) {..}else if {..} else{..}
– Else optional● Switch is used for selecting from multiple code blocks
– case and break needed with optional default
![Page 10: JavaScript Comments and Conditionals](https://reader036.vdocuments.net/reader036/viewer/2022081414/54b7abcd4a79594b258b468a/html5/thumbnails/10.jpg)
Next: Iterations