Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
135 views
in Technique[技术] by (71.8m points)

javascript - A carriage return string length can be equal to zero?

I wonder if a string that contains only a carriage return can have its length = 0.

What are the lengths of , , and ?

I think in my app i have detected such as cases but i'm not sure. I have to make sure i'm writting correct conditions when trying to detect empty strings and those with carriage return in them.

Cheers

question from:https://stackoverflow.com/questions/65844425/a-carriage-return-string-length-can-be-equal-to-zero

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The lengths are 1, 1 & 2 as can easily be demonstrated.

console.log(`
`.length);
console.log(`
`.length);
console.log(`
`.length);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...