Filed In:
JavaScript By Example
A series of tutorials that show you how to perform many common tasks in JavaScript
- Objects (9)
- Functions (7)
- Events (10)
- Browser Object Model (11)
- Document Object Model (45)
- Cookies (9)
- Error Handling (6)
- Using Functions (11)
- Object Oriented (24)
1. First JavaScript
The first in a series of examples in how to use JavaScript. This example shows the best way to attach your JavaScript into your web page.
2. Noscript
In this second "JavaScript by Example" we look at the best way of catering for those visiitors who do not have JavaScript.
3. Swapping Content
In this example JavaScript we look at how to use JavaScript to quickly and easily swap what is displayed in a part of the web page.
4. Optional Semi-Colons
This example demonstrates why even though semicolons on the end of statements are optional in JavaScript that best practice its to always include them.
5. Comments
This example shows the various appropriate ways to comment your JavaScript.
6. Variables
In this example we look at where and how you should define variables in JavaScript.
7. Operators
In this example we look at how to use operators in JavaScript and also at how JavaScript determines when + means add and when it means concatenate.
8. IF Statements
This example shows you how to use a simple if statement in your JavaScript so as to make a decision about whether or not to run certain code.
9. Else
This example shows you how to add an else to your if statement so as to run one of two pieces of code depending on the result of the comparison.
10. Blocks
This example shows how you can create a block of statements to substitute anywhere a single statement can go.
11. Switch
This example shows how to use a JavaScript switch statement to provide more than two alternative paths.
12. Switch - Grouping Case
In this JavaScript example we look at how to group values together inside a switch statement so as to run the same code for multiple values.
13. Ternary Operator
The ternary operator provides a shorter way of writing some JavaScript if statements as this example demonstrates.
14. Whitespace
In JavaScript there are lots of places in the code where whitespace is optional. You can include it to make the script easier to read or exclude it to make the script faster to load.
15. Functions
JavaScript functions allow us to separate out code that performs a specific task and to then run that code as and when required using a single statement.
16. Scope
Once we introduce functions into our JavaScript we can define different scopes in which specific variables will exist.
17. For Loop
The for loop is perhaps the most commonly used of the various loop constructs available in JavaScript.
18. While Loop
A JavaScript while loop is simpler in its operation than a for loop and in many cases will also be easier to understand.
19. Do While Loop
A do-while loop will run the code inside the loop at least once since it performs the test for whether to exit the loop at the end of the loop instead of at the start.
20.Loop Break
You can exit early out of any loop in JavaScript by using the break statement.
21. Continue
The continue statement when used inside a loop allows you to skip over the rest of the code in this iteration through the loop and to start the next iteration.
22. Objects
JavaScript has a number of useful objects built into the language and you can also create your own.
23. For..In
The for..in loop is specifically designed for use with JavaScript objects so as to allow you to access all of the properties and methods without even needing to know how many there are or what they are called.
24. Feature Sensing
It is never necessary to know what browser is being used in order to avoid trying to run code that the browser doesn't understand. Since JavaScript was first created it has had the ability to test whether the browser supports the code before running it.
