Calculate the Length of a String Without using Inbuilt methods.

Here in this situation, we will calculate the length of the string without using inbuilt functions. We will solve this problem using a while loop, here we will use a counter that will count the number of elements before the null character and an integer variable 'i' that will keep track of the index and traverse the string by incrementing the 'i'. Let's take a string 'ravi' in this example.
function lenOfStr(q){

    // here q is a parameter which contains string.
    let counter=0;

    let i=0;

    while(q[i]!==undefined){
        counter++;
        i++
    }

    return `The length of the string is ${counter}`

    // here template literal is used , read about template literals.
}

console.log(lenOfStr('ravi'));

Output: The length of the string is 4.