The first part of an 8 part series covering the basics of the JavaScript language. This presentation covers variables, conditionals, loops and functions.
3. Variables are...
• Storage Containers for Data
• Someone’s name
• A username/password
• The current time
• ... or anything else your application needs
22. function add (num1, num2) {
return num1 + num2;
}
var sum1 = add(2, 2);
var sum2 = add(42, 10);
var sum3 = add(123, 0);
23. Review
• Variables...
• Store data
• Begin with a var
• Are given names
• Are assigned values with =
24. Review
• Conditionals...
• Fork code execution based on a
condition
• Begin with an if
• Condition enclosed in (parenthesis)
• Blocks are enclosed in {curly braces}
26. Review
• Loops...
• Repeatedly execute blocks of code
• Execute conditionally
• Come in many flavors:
• while, for, for in, do while
27. Review
• Functions...
• Store code for later use
• Can accept input parameters
(arguments).
• Can send output (return values).
28. Homework
• Build a micro-library which performs basic
math operations
• Functions should accept arguments and
return the result of the math operation