• code

    JavaScript Arrow Functions

    Use Arrow Functions to Write Concise Anonymous Functions In JavaScript, we often don’t need to name our functions, especially when passing a function as an argument to another function. Instead, we create inline functions. We don’t need to name these functions because we do not reuse them anywhere else. To achieve this, we often use the following syntax: ES6 provides us with the syntactic sugar to not have to write anonymous functions this way. Instead, you can use arrow function syntax: When there is no function body, and only a return value, arrow function syntax allows you to omit the keyword return as well as the brackets surrounding the code. This helps simplify…

  • code

    JavaScript Let Keyword

    One of the biggest problems with declaring variables with the var keyword is that you can overwrite variable declarations without an error. Here the console will display the string David. As you can see in the code above, the camper variable is originally declared as James and then overridden to be David. In a small application, you might not run into this type of problem, but when your code becomes larger, you might accidentally overwrite a variable that you did not intend to overwrite. Because this behavior does not throw an error, searching and fixing bugs becomes more difficult.A new keyword called let was introduced in ES6 to solve this potential issue with the var keyword. If you were to replace var with let in the…