Question: 1 / 155

When logging the types in the following code: let s_prim = 'foo'; let s_obj = new String(s_prim); what will the output be?

String, String

Object, String

String, Object

In the given code snippet, `let s_prim = 'foo';` defines a primitive string, while `let s_obj = new String(s_prim);` creates a String object using the primitive string as the initial value.

When you log the types of `s_prim` and `s_obj`, the `typeof` operator is used in JavaScript, which determines the type of a variable:

1. For `s_prim`, since it is a primitive string, using `typeof s_prim` will return `"string"`.

2. For `s_obj`, since it is an instance of the String object created with the `new` keyword, using `typeof s_obj` will return `"object"`.

Thus, when you log the types of both variables, the output will indicate that the first is a primitive string and the second is an object type created from the String constructor. This results in the output being "String, Object," signifying the expected types produced by the `typeof` operator for each variable.

Object, Object

Next

Report this question