JQuery Error Message Unterminated string literal

Posted on

Another article is written which is made to discuss an error triggered upon accessing a web page with a snippet code of JQuery inside in it. It is actually a simple error and it can be solved quickly. The error triggered itself is “unterminated string literal”. This error can be seen in the following image as shown below :

JQuery Error Message Unterminated string literal
JQuery Error Message Unterminated string literal

In the above image, there is a snippet code shown as follows :

alert("clicked !');

The above snippet code is triggering an error of ‘unterminated string literal’. The main purpose of the snippet code above is simply just popping a window with a string ‘clicked !’ on it. The above error can be shown using a tool installed as an additional plugin in a Web Browser. Off course those kind of errors can only be seen in such kind of tool or plugin since the error itself is generated from executing a client-side script such as JQuery which is originally a Javascript client-side scripting.

The image which is shown above is depicting the image of Firebug, an actual plugin installed in a Web Browser named ‘Firefox’. There might be another kind of plugin available in other kind of Web Browser off course which is provided for debugging and correcting errors related to the execution of client-side script.

So, in the above error triggered, there is just one way to solve the problem of the snippet code shown above. Just change the snippet code of

alert("clicked !');

into the following one :

alert("clicked !");

It is obvious since the quote enclosing string is different between the beginning quote enclosing the string with the ending quote enclosing the string. Because it is different, it is considered unterminated or unfinished. So, in order to finish or solve the problem, it needs to be terminated or to be finished by simply correcting the quote type. Just change the quote in the ending quote from a single quote into a double quote. Another way which can be achieved is shown below :

 

alert("clicked !');

into the following one :

alert('clicked !");

It is one way or another by balancing the quote type. In the above context, it is achieved by simply changing the beginning quote from a double quote into a single quote. So, the quote type is balanced and it will not considered unterminated again.

Leave a Reply