Thursday, January 29, 2026
HomeLanguagesJavascriptJavaScript Error.prototype.fileName Property

JavaScript Error.prototype.fileName Property

The fileName is a non-standard property that contains the path of the file that raised this error. It is recommended to not use this property on production sites facing the web, as it may not work for every user.  If called from the Firefox Developer Tools, “debugger eval code” is returned. This property is one of the parameters, which is passed during creating an error object.

Syntax:

errorObj.fileName

Property value:  Path of the file containing code that raised this error.

Return Value: It returns a string, representing the path of the file containing code that raised this error.

Example 1:

Javascript




<script>
try {
    var err = new Error ("Could not parse file");
    if(err.fileName == undefined)
        err.fileName = "/Users/abhinavjain194/desktop/GFG/err.js"
    throw err;
}
catch(e) {
    console.log ("Error: " + e.message);
    console.log ("The Error occurred at " + e.fileName);
}
</script>


Output:

Error: Could not parse file
The Error occurred at /Users/abhinavjain194/desktop/GFG/err.js

Example 2:

Javascript




<script>
try {
    var err = new Error ("Unexpected token output");
    if(err.fileName == undefined)
        err.fileName = 
            "/Users/abhinavjain194/desktop/GFG/token_err.js"
    throw err;
}
catch(e) {
    console.log ("Error: " + e.message);
    console.log ("The Error occurred at " + e.fileName);
}
</script>


Output:

Error: Unexpected token output
The Error occurred at /Users/abhinavjain194/desktop/GFG/token_err.js

Supported Browsers:

  • Google Chrome
  • Firefox
  • Safari
  • Opera
  • Internet Explorer

We have a complete list of Javascript Errors, to check those please go through the JavaScript Error Object Complete Reference article.

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32476 POSTS0 COMMENTS
Milvus
122 POSTS0 COMMENTS
Nango Kala
6848 POSTS0 COMMENTS
Nicole Veronica
11978 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12065 POSTS0 COMMENTS
Shaida Kate Naidoo
6986 POSTS0 COMMENTS
Ted Musemwa
7221 POSTS0 COMMENTS
Thapelo Manthata
6934 POSTS0 COMMENTS
Umr Jansen
6916 POSTS0 COMMENTS