Change location for data files
This commit is contained in:
1 parent
b741a0e1ee
commit
b6a0255f12
2772 files changed
+30
-30
No files matched your search
+5
@@ -0,0 +1,5 @@
|
||||
# Throw Statement
|
||||
|
||||
The throw statement throws a user-defined exception. Execution of the current function will stop (the statements after throw won't be executed), and control will be passed to the first catch block in the call stack. If no catch block exists among caller functions, the program will terminate. (excerpt from MDN)
|
||||
|
||||
Visit the following resources to learn more:
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
# Try, Catch, Finally
|
||||
|
||||
These are ways of handling errors in your JavaScript code. Inside the try code block we have the code to run, inside the catch block we handle the errors, and inside the finally block we have code that runs after the execution of the previous code blocks, regardless of the result.
|
||||
|
||||
Visit the following resources to learn more:
|
||||
|
||||
- [JavaScript Errors](https://www.w3schools.com/js/js_errors.asp)
|
||||
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
# Utilizing error objects
|
||||
|
||||
When a runtime error occurs, a new `Error` object is created and thrown. With this `Error` object, we can determine the type of the Error and handle it according to its type.
|
||||
|
||||
## Types of Errors:
|
||||
|
||||
Besides error constructors, Javascript also has other core Error constructors.
|
||||
|
||||
- [AggregateError](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AggregateError)
|
||||
- [EvalError](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError)
|
||||
- [InternalError](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/InternalError)
|
||||
- [RangeError](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError)
|
||||
- [ReferenceError](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError)
|
||||
- [SyntaxError](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError)
|
||||
|
||||
## Example
|
||||
|
||||
```js
|
||||
try {
|
||||
willGiveErrorSometime();
|
||||
} catch (error) {
|
||||
if (error instanceof RangeError) {
|
||||
rangeErrorHandler(error);
|
||||
} else if (error instanceof ReferenceError) {
|
||||
referenceErrorHandle(error);
|
||||
} else {
|
||||
errorHandler(error);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Visit the following resources to learn more:
|
||||
|
||||
- [Error Object - MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)
|
||||
- [Control flow & Error handling - MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Control_flow_and_error_handling)
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
# Exception Handling
|
||||
|
||||
In JavaScript, all exceptions are simply objects. While the majority of exceptions are implementations of the global Error class, any old object can be thrown. With this in mind, there are two ways to throw an exception: directly via an Error object, and through a custom object. (excerpt from Rollbar)
|
||||
|
||||
Visit the following resources to learn more:
|
||||
|
||||
- [Throwing Exceptions in JavaScript](https://rollbar.com/guides/javascript/how-to-throw-exceptions-in-javascript)
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
# If else
|
||||
|
||||
The `if` statement executes a statement if a specified condition is `truthy`. If the condition is `falsy`, another statement in the optional `else` clause will be executed.
|
||||
|
||||
## Example
|
||||
```js
|
||||
if (condition) {
|
||||
statement1
|
||||
} else {
|
||||
statement2
|
||||
}
|
||||
```
|
||||
|
||||
Visit the following resources to learn more:
|
||||
|
||||
- [if...else - MDN docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else)
|
||||
- [Conditional branching: if, ? - javascript.info](https://javascript.info/ifelse)
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
# Switch Case
|
||||
|
||||
The `switch` statement evaluates an expression, matching the expression's value against a series of `case` clauses, and executes statements after the first `case` clause with a matching value, until a `break` statement is encountered. The `default` clause of a `switch` statement will be jumped to if no `case` matches the expression's value.
|
||||
|
||||
## Example
|
||||
```js
|
||||
switch (expression) {
|
||||
case value1:
|
||||
//Statements executed when the result of expression matches value1
|
||||
break;
|
||||
case value2:
|
||||
//Statements executed when the result of expression matches value2
|
||||
break;
|
||||
...
|
||||
case valueN:
|
||||
//Statements executed when the result of expression matches valueN
|
||||
break;
|
||||
default:
|
||||
//Statements executed when none of the values match the value of the expression
|
||||
break;
|
||||
}
|
||||
```
|
||||
|
||||
Visit the following resources to learn more:
|
||||
|
||||
- [switch - MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/switch)
|
||||
- [The `switch` Statement: Why, What and How - CodeGuage](https://www.codeguage.com/courses/js/conditions-switch)
|
||||
- [The switch statement - javascript.info](https://javascript.info/switch)
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
# Conditional statements
|
||||
|
||||
When you write code, you often want to perform different actions for different decisions. You can use conditional statements in your code to do this. In JavaScript, we have three conditional statements: `if`, `if...else`, and `switch`.
|
||||
|
||||
Visit the following resources to learn more:
|
||||
|
||||
- [Making decisions in your code — conditionals](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/conditionals)
|
||||
- [Conditional branching: if, ?](https://javascript.info/ifelse)
|
||||
@@ -0,0 +1,13 @@
|
||||
# Control Flow
|
||||
|
||||
In JavaScript, the `Control flow` is a way of how your computer runs code from top to bottom. It starts from the first line and ends at the last line unless it hits any statement that changes the control flow of the program such as loops, conditionals, etc.
|
||||
|
||||
We can control the flow of the program through any of these control structures:
|
||||
- Sequential (default mode)
|
||||
- Conditional Statements
|
||||
- Exception Handling
|
||||
- Loops and Iterations
|
||||
|
||||
Visit the following resources to learn more:
|
||||
|
||||
- [Control Flow - MDN](https://developer.mozilla.org/en-US/docs/Glossary/Control_flow)
|
||||
Reference in new issue
Block a user