Question: When I paste the following script between `<script></script>` inside the html document it works fine. 

However, when I load it through `<script src="example.js></script>` it only partially runs (the first section runs but the second does not).

Here is the code:

```
//SMOOTH SCROLL
  $(function() {
  $('a[href*="#"]:not([href="#"])').click(function() {
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
      var target = $(this.hash);
      target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
      if (target.length) {
        $('html, body').animate({
          scrollTop: target.offset().top
        }, 1000);
        return false;
      }
    }
  });
});
// End of SMOOTH SCROLL

//NAV ENLARGE
$(window).on('scroll', function () {
  var scrollTop = $(window).scrollTop();
    if (scrollTop > 1) {
      $('#main-navigation').stop().animate({height: "10vh"},100);
      $("#main-navigation").css("position", "fixed");
      $("#main-navigation").css("top", "0");
      $('#main-navigation').css("width", "100vw");
    }
    else {
      $('#main-navigation').stop().animate({height: "100vh"},100);  
      $("#main-navigation").css("position", "static");
    }
});
//End NAV ENLGAR

```

Answer: 
I'm sumarizing comments and some additional research:

Simple anwer: currently impossible
==================================

There is currently no cross-platform way to retrive syntax error position from `new Function()` or `eval()` call.

Partial solutions
=================

1. Firefox support non-standard properties `error.lineNumber` and `error.e.columnNumber`. This can be used with feature detection if position of error is not critical.
2. There are filled bug reports/feature request for v8 that could bring support of (1) to chrome/node.js: Issue [#1281](https://bugs.chromium.org/p/v8/issues/detail?id=1281), [#1914](https://bugs.chromium.org/p/v8/issues/detail?id=1914), [#2589](https://bugs.chromium.org/p/v8/issues/detail?id=2589)
3. Use separate javascript parser, based on [JSLint](http://www.jslint.com/) or [PEG.js](http://pegjs.org/).
4. Write custom javascript parser for the job.

Solutions 1 and 2 are incomplete, rely on features that are not part of standard. They can be suitable if this information is a help, not an requirement.

Solution 3 depends on external codebase, which was explicitly required by original question. It is suitable if this information is required and larger codebase is acceptable compromise.

Solution 4 is impractical.

Credits: @user3896470, @ivan-kuckir, @aprillion
**Solution for browser:**

You can use latest Firefox to get the required information like error line number and column number inside the string. 

Example:

```
  var testWithSyntaxError = "{\n\n\n\nvar x=3;\n =2;}";

  try {
      var f=new Function('',testWithSyntaxError);
  } catch(e) {
    console.log(e instanceof SyntaxError); 
    console.log(e.message);               
    console.log(e.name);                
    console.log(e.fileName);            
    console.log(e.lineNumber);           
    console.log(e.columnNumber);         
    console.log(e.stack);               
  }

```

Output in Firefox console:

```
  undefined
  true
  expected expression, got '='
  SyntaxError
  debugger eval code
  6
  1
  @debugger eval code:4:11

```

Where 6 is the line number and 1 is the column number of error inside the string.

It won't work in Chrome. There are bugs filed regarding this issue for chrome browser. See:

<https://bugs.chromium.org/p/v8/issues/detail?id=1281>

<https://bugs.chromium.org/p/v8/issues/detail?id=1914>

<https://bugs.chromium.org/p/v8/issues/detail?id=2589>