function strLength(s) { var length = 0; while (s[length] !== undefined){ length++; } return length; } console.log(strLength("Hello")); // 5 console.log(strLength("")); // 0