Complete the code to get the length of the string.
const str = 'hello'; const length = str.[1]; console.log(length);
len or size which are not valid for strings in JavaScript.The length property returns the number of characters in a string in JavaScript.
Complete the code to access the first character of the string.
const word = 'world'; const firstChar = word[1]; console.log(firstChar);
In JavaScript, strings can be accessed like arrays using square brackets [] with the index inside.
Fix the error in the code to convert the string to uppercase.
const text = 'hello'; const upper = text.[1](); console.log(upper);
touppercase() or incomplete method names.The correct method to convert a string to uppercase in JavaScript is toUpperCase() with exact casing.
Fill both blanks to create a new string by repeating 'ha' three times.
const laugh = 'ha'.[1]([2]); console.log(laugh);
concat which joins strings but does not repeat.The repeat() method repeats a string a specified number of times. Here, repeating 'ha' 3 times gives 'hahaha'.
Fill all three blanks to extract 'cat' from the string 'concatenate'.
const word = 'concatenate'; const part = word.[1]([2], [3]); console.log(part);
substr which takes start and length, not end index.The slice(start, end) method extracts characters from start index up to but not including end. Here, slice(3, 6) extracts 'cat'.
