// Copy and paste me to your console 'Hello World! 👋'
It looks like valid code, but there is an invisible character at the end of the string, which can cause the above error. Now try to paste the same code into JsFiddle or VSCode. These editors will highlight the invisible character so you will know exactly where to look.
In order to fix the error, simply remove the invalid character by deleting it. The same error can also happen if similar, but not the same characters are used for operators or reserved characters. Take a look at another code examples:
// Uses invalid quotations. Notice the difference between “”, and "" “Hello World! 👋” // Uses –, instead of - 1 – 1 // Using ;, instead of ; which looks exactly the same, but they are different characters "Hello World! 👋";
All of these contain invalid characters, even though they might be hard to spot at first. The first example is also incorrectly highlighted since it is not a string. The second may also be visible to some, but the third is indistinguishable from a real semicolon.
This is also noted in VSCode: " The character
;" could be confused with the character
;", which is more common in source code".
If your IDE does not highlight anything, you can try to paste the code into an online editor such as JsFiddle, or just completely delete the line that breaks, and retype it.Remove ads
📚 Get access to exclusive content
Want to get access to exclusive content? Support webtips with the price of a coffee to get access to tips, checklists, cheatsheets, and much more. ☕Get access