wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

JavaScript String Methods

Total questions: 15

Worksheet time: 10mins

Name
Class
Date
1.

let string = "foo"

How to determine the length of the string?

(a)  

2.

let string = "The cat is black"

How to find the index/position of "cat" in the string

(a)  

3.

let string = "The black cat is black"

How to find the LAST index/position of "black" in the string

(a)  

4.

let string = "Milk, chocolate, cookies"

How to extract a new string "chocolate, cookies" from the first string

(a)  

5.

let string = "Milk, chocolate, cookies"

How to replace "chocolate" with "banana"?

(a)  

6.

let string = "Milk, chocolate, cookies"

How to figure out what character is on the 3rd position of the string?

(a)  

7.

let string = "Milk, chocolate, cookies"

How to convert the string to upper case?

(a)  

8.

let string = "Milk, chocolate, cookies"

How to convert the string to lower case?

(a)  

9.

let string = " Hello World! "

How to trim the whitespaces around "Hello World!" ?

(a)  

10.

let stringOne = "Milk"

let stringTwo = "chocolate"

Which operations below can be used to make a new string that says: "Milk, chocolate" using the variables.

a)

stringOne + ", " + stringTwo

b)

stringOne + ', ' + stringTwo

c)

`${stringOne}, ${stringTwo}`

d)

stringOne.concat(", ", stringTwo)

e)

all of the above

11.

let string = "a, b, c, 1, 2, 3"

How to convert this string into the array: ["a", "b", "c", "1", "2", "3"]?

(a)  

12.

let string = "chocolate milk banana"

How to convert this string into the array: ["chocolate", "milk", banana"]?

(a)  

13.

let string = "chocolate milk banana"

what will happen to the string if we run the command:

let test = string.split(" ")

a)

test is equal to the string words, split at every character

b)

test is equal to 3 strings, each with one word

c)

test is equal to an array with 3 words

d)

test is equal to an array with 21 characters

14.

let array = ["chocolate", "milk", "cookies"]

what happens when we run the command:


let string = array.join(" ")

a)

string is equal to [chocolate, milk, cookies]

b)

string is equal to "chocolate milk cookies"

c)

string is equal to "chocolatemilkcookies"

d)

string is equal to "chocolate", "milk", "cookies"

15.

let string = "milk, chocolate, cookies"

How to get a boolean indicating if the string includes the word "cookies"


HINT: the command should return true or false

(a)