Open In App

Visual studio code doesn’t give out error if parents function didn’t close correctly

Visual Studio Code (VS Code) is a popular code editor used by many developers worldwide. It provides several features and functionalities for developers to write efficient and error-free code. However, sometimes it can be frustrating when an error in your code doesn’t display in the editor, especially if it’s caused by a common mistake like an unclosed parent function. In this article, we’ll see possible reasons for not getting errors after the parent’s function didn’t close correctly, & accordingly, we will see the different approaches to resolve it.

The problem is Visual Studio Code doesn’t give an error message for an unclosed parent function, which can cause confusion and make it challenging to find and fix errors in your code. This can lead to potentially introducing bugs into your code, as well as wasted time and effort in fixing the bug.



There are several reasons for causing the error:

Example: This example illustrates getting an error message in the terminal of vs code. Here, we have two functions, i.e., the Parent_Geek() and Child_Geek(), & the Parent_Geek() calls Child_Geek() to perform some tasks. However, in the Parent_Geek(), we missed closing the curly brace. This means that the Parent_Geek() did not close correctly.






function Parent_Geek() {
    console.log("Parent Geek function started");
    Child_Geek();
    // }  // Removed Closing Brace.
 
    function Child_Geek() {
        console.log("Child Geek function started");
        console.log("Child Geek function ended");
    }
 
Parent_Geek();

You might expect Visual Studio Code to give you an error for the unclosed function. However, in some cases, you might not get an error at all. This can be confusing and make it difficult to find and fix errors in your code. If you are writing a long code. When we run this code in Visual Studio Code, we get the following output:

Output:

VS CODE OUTPUT ERROR

The following ways are illustrated to resolve the error:




function Parent_Geek() {
    console.log("Parent Geek function started");
    Child_Geek();
} // Added Closing Curly Brace
 
function Child_Geek() {
    console.log("Child Geek function started");
    console.log("Child Geek function ended");
}
 
Parent_Geek();

In this corrected code, we have added the missing closing curly brace for the Parent_Geek() function. Now, when we run the code in Visual Studio Code, we will get the following output:

Output
Parent Geek function started
Child Geek function started
Child Geek function ended

 

ESLInt Extension Installation

Checking Error through Browser Console

In conclusion, Visual Studio Code may not give an error for an unclosed parent function due to a variety of reasons, such as syntax errors, missing closing braces, and incorrect indentation. This can be frustrating for developers, but it’s essential to understand why it happens and how to resolve the issue. By ensuring proper code formatting and using tools like linters and debuggers, developers can catch errors that might be missed by the Visual Studio Code language service. Testing the code thoroughly is crucial to ensure that it is error-free and working correctly.


Article Tags :