16

This function gives me the following error:

SyntaxError: Invalid character '\u8203'

All looks good to me,

function changeColumnWidth() {
    var w = Math.random() * 200+80;
    $('#menu').css("width", w+"px");
}​

can someone spot the error?

clankill3r
  • 9,146
  • 20
  • 70
  • 126

2 Answers2

32

It's a character after the closing curly brace:

I copy-pasted your code in Firefox' console, postfixed with a undefined method invocation:

'function changeColumnWidth() {\
    var w = Math.random() * 200+80;\
    $(\'#menu\').css("width", w+"px");\
}​'.l(); /* .l() triggers a TypeError, since it's not defined */

A TypeError (undefined) shows up, which includes the parsed (escaped) code:

TypeError: "function changeColumnWidth() { var w = Math.random() * 200+80; $('#menu').css(\"width\", w+\"px\");}\u200B".l is not a function.
                                 ^^^^^^ Here's the error.

Now, the troublemaker is found. To fix it, open your code in a text editor, and remove the invisible character. This character can be detected by walking through all characters using the arrow keys.

Rob W
  • 341,306
  • 83
  • 791
  • 678
  • 1
    FYI, for long blocks of code, adding a backslash at the end of every line is not funny. That's why I'm using E4X (Firefox-only) to mark a block: `<![CDATA[ ... code here ... ]]>.toString().l()` – Rob W Aug 23 '12 at 08:31
  • I have huge javascript that i copied from net how to find those errors ? is there any editor that has find method ? – user1788736 Oct 15 '17 at 19:29
0

Open file in Hex Editor (I m using Hex Friend ,http://ridiculousfish.com/hexfiend/) Remove the character which is showing error Save file

Vipul R
  • 195
  • 2
  • 9