Many languages have an 'IsSpace' or similar function in the library. JavaScript doesn't, for some reason, but that doesn't stop you writing your own.
I should confess - I don't use JavaScript much, so I could be out of date on this.
Don't forget that line ends are platform dependent. On Windows, you get a carriage return and a linefeed. On old macs (before OS X, IIRC) the line end was a carriage return without a linefeed. Either way, it's best to count \r as whitespace. \v (vertical tab) is also sometimes included. In unicode, you may also need to worry about such beasts as en-spaces, em-spaces, non-breaking spaces etc.
You may be better off using a regular expression (assuming there's a match-any-whitespace), or using a strip-whitespace function and seeing what's left after.