Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I rectify " Expected String instead saw "" " using jslint?

Tags:

jslint

I've got a regular expression:

return (str+'').replace(/^(.)|\s(.)/g, function ( $1 ) { return $1.toUpperCase ( ); } );

I get following jslint error:

Expected String instead saw ""

How can I rectify this error?

like image 820
starjava Avatar asked May 29 '12 06:05

starjava


2 Answers

It wants you to use

String(str)

isntead of

(str+'')

Invoking the String function as a "cast" is a slightly cleaner way to convert something to a string from some other type.

like image 180
peterflynn Avatar answered Nov 10 '22 10:11

peterflynn


Use toString();
(new Date()).getTime()+""; instead (new Date()).getTime().toString();
like image 36
srikanth_yarram Avatar answered Nov 10 '22 09:11

srikanth_yarram