Quick Reference
This is a quick reference list of JavaScript statements with examples of how they are used.
- JavaScript – break StatementThe break statement stops code execution within the switch, and also breaks out of a loop, continuing to execute code that comes after the loop.
- JavaScript – class StatementThe class statement initiates a class with properties and methods assigned in the constructor() method.
- JavaScript – const StatementThe const statement declares a variable (container for storing information) with an immediately defined value that will not change.
- JavaScript – continue StatementThe continue statement breaks an iteration in the loop, if a specified condition occurs, and then continues with the next iteration in the loop.
- JavaScript – debugger StatementThe debugger statement stops the execution of a script and calls the debugger. If debugging is unavailable, the statement has no effect.
- JavaScript – do…while StatementThe do…while statement defines a code block to be executed at least once, and repeated as long as a condition is true.
- JavaScript – for StatementThe for statement defines a block of code to be executed as long as a specified condition is true.
- JavaScript – for…in StatementThe for…in statement loops over the properties of an object, executing a block of code inside the loop once for each item found.
- JavaScript – for…of StatementThe for…of statement loops over the values of any iterable, executing a block of code inside the loop once for each item found.
- JavaScript – function StatementThe function statement declares a function to be executed later, when it is called. Functions are objects, and have both properties and methods.
- JavaScript – if…else StatementThe if…else statement executes a block of code if a specified condition is true, and optionally, another block of code if false.
- JavaScript – let StatementThe let statement declares a variable (container for storing information), and can be empty when declared, with the value assigned later.
- JavaScript – switch StatementThe switch statement executes different blocks of code depending on set conditions, and uses the break keyword to break out of the switch block.
- JavaScript – throw StatementThe throw statement allows you to generate a custom error (throw an exception), which can be a String, a Number, a Boolean, or an Object.
- JavaScript – try…catch…finally StatementThe try…catch…finally statement handles errors without stopping JavaScript to output the error.
- JavaScript – var StatementThe var statement declares a variable (container for storing information), and can be empty when declared, with the value assigned later.
- JavaScript – while StatementThe while statement defines a code block to be executed for as long as a condition is true.
JavaScript Notes:
- When using JavaScript, single or double quotation marks are acceptable and work identically to one another; choose whichever you prefer, and stay consistent
- JavaScript is a case-sensitive language; firstName is NOT the same as firstname
- Arrays count starting from zero NOT one; so item 1 is position [0], item 2 is position [1], and item 3 is position [2] … and so on
- JavaScript variables must begin with a letter, $, or _
- JavaScript variables are case sensitive (x is not the same as X)
We’d like to acknowledge that we learned a great deal of our coding from W3Schools and TutorialsPoint, borrowing heavily from their teaching process and excellent code examples. We highly recommend both sites to deepen your experience, and further your coding journey. We’re just hitting the basics here at 1SMARTchicken.