JS Built-ins
← String191 / 195
StringString.prototype.lengthbeginner

String.prototype.length β€” basic length

πŸ“– Usage Example
'hello'.length    // β†’ 5
''.length         // β†’ 0
'πŸ˜€'.length       // β†’ 2

The length property returns the number of UTF-16 code units in the string.

String.prototype.length

str.length is a read-only property that returns the number of UTF-16 code units in the string.

Challenge: Implement strLen(str) that returns the length of the string.

strLen('hello') // β†’ 5
strLen('hi')    // β†’ 2
πŸ’‘ Hints (1)
  • β€’ `str.length` is a property, not a method β€” no parentheses needed.