Variables are data containers used to store information that can be referred to in later scripts. Commonly used variables include strings, numbers and boolean values. Understanding how variables are declared, what value types they can store, and how they are named is essential for writing and debugging scripts.
Functions are reusable chunks of code that perform specific tasks when they are executed. Common functions include math-based operations like rounding numbers or removing decimals; string manipulation like finding the length of a string, removing white space from the ends of a string; and DOM manipulation like setting an element’s inner HTML. Understanding how to write functions is important for writing efficient scripts.
Writing efficient code involves understanding the fundamentals of the language, so that you can write code that is more optimized. This includes using shorter variable names (so as not to exceed an unnecessary amount of characters), using fewer instructions (so that your code can run faster), understanding how to work with loops (for snippets of code that need to be repeated multiple times), as well as understanding how to cache elements (so that your code can run faster). Understanding these concepts is essential for writing efficient code.
When working with web development, there may be times when you encounter common issues such as errors thrown by mistakes in syntax or semantics, unexpected outputs or browser compatibility issues. To navigate through these issues effectively, you need to have a good understanding of error diagnosing techniques such as debugging and logging. This means taking a step back from your code, looking at it from a different perspective and trying different approaches until you identify the problem and repair your code.