5 things Javascript Programmers need to know
1. The original value:In JavaScript, a primitive value or primitive type is data that is not an object and has no methods.
There are seven raw data types/values, which are:
-
Undefined, unintentionally missing or Undefined value
-
Null (Null), an intentionally missing or defined value
-
Booleans (true and false), values of logical operations
-
Numbers (-100, 3.14, etc.), numerically calculated values
-
Strings (” Hello, “” Abracadabra,” and so on), representing the value of the text
-
Symbols (uncommon, introduced after ES2015), is usually used to hide details
-
BigInt (uncommon, introduced after V8, ES2020), for large number operations
2. Error handling:No matter how good our code is, we will face many errors in the process of coding. Errors can be caused by our mistakes, unexpected user input, incorrect server responses, and a thousand other reasons.
The statement “a try… “Catch” is often used to handle these errors. It allows us to “catch” errors so that the program can do something more reasonable than quit.
3. * * “the Try… How does catch work
“Try… The catch syntax has two main blocks, ‘try blocks’ and ‘catch blocks’.
Here’s how it works:
First, execute the try statement {… }.
If there is no error, catch(err) is ignored: the execution completes the other work.
If an error occurs, the try execution is stopped and the flow to the beginning of the catch (err) is controlled.
The ERR variable will contain an error object that contains details about what happened.
4. Coding style:Coding styles are important to programmers. Code should be clean, easy, and easy to read. A good code style helps the program run. Here are some code style criteria:
- Leave a space before the opening parenthesis
- There should be a space between the open parentheses and the curly braces
- Instead of writing a long line of code, it’s best to break it up
- Each statement should be followed by a semicolon
- Try to avoid code nesting too deeply
- Declare functions before the code that uses them
- Place the closing parenthesis on a new line without Spaces
- Always end the object definition with a semicolon
- Use linter tools that automatically check code styles
Here’s a cheat sheet with some suggested rules:
5. Comments: Comments in code are also important to apes.
Apes often use comments to describe how and why code works, so comments should be obvious, clean, and easy to understand.
There are two types of comments: “good comments” and “bad comments.”
- Good note:
Good comments are clean and easy to understand. In short, it provides a high-level overview of the components, explaining how they interact in various situations, what the flow of control is, and how the different parts work together.
- Bad comments:
Complex, long and beside the point.
Here are some suggestions for comments:
This is recommended:
- From the overall architecture, high-level view.
- Function usage.
- Important solutions, with special emphasis on uncommon scenarios.
Avoid doing this:
- Tell “how the function works” and “what it does”.
- Written comments do not make the code easy to understand or self-describe.