starjava
starjava

Reputation: 443

How can I rectify " Expected String instead saw "" " using 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?

Upvotes: 9

Views: 3910

Answers (2)

srikanth_yarram
srikanth_yarram

Reputation: 957

Use toString();
(new Date()).getTime()+""; instead (new Date()).getTime().toString();

Upvotes: 2

peterflynn
peterflynn

Reputation: 4906

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.

Upvotes: 10

Related Questions