Category: Javascript
-
[Javascript] Closure
What is a Closure? In simple terms, an inner function captures the context of the outer function. But, what is a context? The context refers to the environment in which a function is declared. This environment includes any variables, parameters, and functions that are within the scope of the function when it is defined. When…
-
[Javascript] Controlling code flow (3)
try, catch, and finally When we try to handle errors, try-catch statement is a good option. However, it isn’t clear how the error is caught in catch block. Furthermore, it is trickier when finally block is included. We do know that finally block must be executed after try and catch block, but the code flow…
-
[Javascript] Controlling code flow (2)
Labeled Statement Labeled statements in JavaScript provide a mechanism for identifying and referencing specific statements within your code. While not frequently used, they can be particularly useful in certain scenarios, such as when working with nested loops or when you need to break out of multiple control structures. Why Do We Need Labels? Labels are…
-
[Javascript] Controlling code flow (1)
Controlling code flow Conditional statement When controlling the flow of our code, we have several options. If we want to execute different blocks of code based on certain conditions, we can use if-else statement. These statements allow us to specify which code block should be executed based on carefully defined conditions. Below, we see see…
-
[Javascript] Hoisting
We already know Hoisting When we write Javascript code, the variables could be used within their scope before they are declared, thanks to hoisting. This feature allows for convenient coding, but it also requires caution as it can lead to unexpected erros and bugs. Javascript hoisting refers to the behavior where variable and function are…