JavaScript …
1. JavaScript Primitive Values —
There are two types of data types in JavaScript:
- Primitive values
- Non-primitive values (object references)
Example of Primitive values —
2. JavaScript Objects —
JavaScript is an object-based language. In JavaScript, almost everything is an object.
- Dates are objects
- Maths are objects
- Regular expressions are objects
- Arrays are objects
- Functions are objects
- Objects are objects
- Booleans can be objects
- Numbers can be objects
- Strings can be objects
There are 3 ways to create objects —
- By object literal
2. By creating an instance of Object directly (using the new keyword)
3. By using an object constructor (using the new keyword)
3. JavaScript Functions —
Functions are Objects. A JavaScript function is defined with the function keyword. The function can be called anywhere in your program.
4. JavaScript Expressions —
A JavaScript function can also be defined using an expression. A function expression can be stored in a variable. Expressions in JavaScript can be divided into categories.
- Arithmetic Expression
- String Expressions
- Primary Expressions
- Array and Object Initializers Expressions
- Logical Expressions
- Left-hand-side Expressions
- Property access Expressions
- Object creation Expressions
- Function definition Expressions
- Invocation Expressions
5. JavaScript Error handling, “try..catch” —
The try statement lets you test a block of code to check for errors.
The catch statement lets you handle the error.
The throw statement lets you create custom errors.
The throw statement lets you make your own errors.
The finally statement lets you execute code, after try and catch. The finally block runs regardless of the result of the try-catch block.
6. JavaScript Comments —
Comments are used to explain the code. It is not executed. The comments also help other developers to understand your code.
- There are two types of comments in JavaScript: single-line and multi-line.
- Single-Line comments — start with //
2. Multi-line comments — start with /* and end with */.
- Good comments —
Avoid unnecessary acronyms. Use the return key. Respond to the article. Use facts. Make it clear who you’re replying to. Don’t be Captain Caps Lock.
Thanks for reading…