Answer: C) Changes all characters to uppercase
Explanation: The `toUpperCase()` method converts all alphabetic characters in a string to uppercase.
Answer: B) HELLO
Explanation: All letters are converted to uppercase, so `"hello"` becomes `"HELLO"`.
Answer: A) toLowerCase()
Explanation: The `toLowerCase()` method converts a string to all lowercase letters.
Answer: A) karachi
Explanation: The `toLowerCase()` method converts `"Karachi"` to `"karachi"`.
Answer: B) It returns the string unchanged
Explanation: Since the string is already uppercase, `toUpperCase()` returns it as is.
Answer: A) name.toUpperCase();
Explanation: The correct syntax is to call the method on the string using dot notation and parentheses.
Answer: A) javascript
Explanation: `toLowerCase()` converts all characters in the string to lowercase.
Answer: C) var newStr = string.toLowerCase();
Explanation: This is the correct way to store the result of the `toLowerCase()` method in a variable.
Answer: A) wow
Explanation: The method `toLowerCase()` changes "WOW" to "wow".
Answer: C) For consistent comparison or display
Explanation: Changing case helps ensure strings match consistently when comparing or displaying text.
Answer: B) The number of characters
Explanation: The `length` property gives the total number of characters in a string, including spaces and punctuation.
Answer: B) 5
Explanation: The string "hello" has 5 characters, so `.length` returns 5.
Answer: C) Extracts a part of the string and returns it
Explanation: The `slice()` method extracts a portion of a string and returns it as a new string.
Answer: A) Java
Explanation: `slice(0, 4)` extracts characters from index 0 up to, but not including, index 4.
Answer: D) orl
Explanation: Characters from index 1 to index 3 are returned: "o", "r", "l".
Answer: B) string.slice(-3)
Explanation: A negative number in `slice()` counts from the end of the string.
Answer: B) 8
Explanation: The string "Welcome!" has 8 characters including the exclamation mark.
Answer: B) It extracts from that index to the end
Explanation: When only one argument is passed to `slice()`, it extracts from that index to the end of the string.
Answer: A) msg.slice(0, 1)
Explanation: `slice(0, 1)` returns a substring starting at index 0 and ending before index 1.
Answer: C) slice()
Explanation: The `slice()` method is widely used to extract parts of a string.
Answer: A) includes()
Explanation: The `includes()` method checks if a string contains a specified substring and returns true or false.
Answer: A) true
Explanation: "Script" is a substring of "JavaScript", so `includes()` returns true.
Answer: B) Returns the index of the first match
Explanation: The `indexOf()` method returns the index of the first occurrence of the specified value, or -1 if not found.
Answer: A) 6
Explanation: The word "world" starts at index 6 in the string "hello world".
Answer: C) -1
Explanation: When the substring is not found, `indexOf()` returns -1.
Answer: A) endsWith()
Explanation: The `endsWith()` method checks if a string ends with the specified value.
Answer: B) true
Explanation: The string "hello.js" ends with ".js", so `endsWith()` returns true.
Answer: C) Returns the last index of a specified substring
Explanation: The `lastIndexOf()` method searches from the end of the string and returns the last occurrence index.
Answer: A) true
Explanation: The last "a" in "abcabc" is at index 3.
Answer: B) false
Explanation: Since "z" is not present in "test", `includes()` returns false.
Answer: A) charAt()
Explanation: The `charAt()` method returns the character at the specified index in a string.
Answer: C) S
Explanation: The character at index 4 in "JavaScript" is "S".
Answer: C) empty string
Explanation: If the index is greater than or equal to the string length, `charAt()` returns an empty string.
Answer: A) h
Explanation: Index 0 corresponds to the first character, which is "h".
Answer: C) string.charAt(string.length - 1)
Explanation: The last character is at the index one less than the stringβs length.
Answer: C) "" (empty string)
Explanation: Index 10 is out of range, so `charAt()` returns an empty string.
Answer: B) at()
Explanation: The `at()` method is a modern alternative that can also take negative indexes.
Answer: A) o
Explanation: Negative index -1 refers to the last character using the `at()` method.
Answer: C) e
Explanation: Index 2 in "OpenAI" is the letter "e".
Answer: A) The first character
Explanation: If no index is given, `charAt()` treats it as 0 and returns the first character.
Answer: C) replace()
Explanation: The `replace()` method is used in JavaScript to replace part of a string with another value.
Answer: A) I like bananas
Explanation: The `replace()` method substitutes "apples" with "bananas" in the original string.
Answer: B) A new string
Explanation: Strings are immutable in JavaScript; `replace()` returns a new string without modifying the original.
Answer: C) First match only
Explanation: By default, `replace()` replaces only the first occurrence unless a global regex is used.
Answer: C) Both A and B
Explanation: You can use `replaceAll()` or `replace()` with a global regular expression like /word/g.
Answer: B) cat cat cat
Explanation: The global regex `/dog/g` replaces all occurrences of "dog" with "cat".
Answer: A) Hello, Universe!
Explanation: "World" is replaced by "Universe" using the `replace()` method.
Answer: A) one 2 three
Explanation: The word "two" is replaced with "2" in the original string.
Answer: D) Both B and C
Explanation: Both `replaceAll()` and `replace()` with global regex can replace all occurrences of "a".
Answer: A) Yes
Explanation: You can chain `replace()` methods to apply multiple replacements in a single expression.
Answer: A) Math.round()
Explanation: `Math.round()` returns the value of a number rounded to the nearest integer.
Answer: B) 5
Explanation: 4.7 is closer to 5, so `Math.round()` returns 5.
Answer: C) Rounds down
Explanation: `Math.floor()` always rounds a number downward to the nearest whole number.
Answer: C) 9
Explanation: `Math.floor(9.8)` rounds the value down to 9.
Answer: C) Rounds up
Explanation: `Math.ceil()` always rounds a number upward to the next largest integer.
Answer: B) 3
Explanation: `Math.ceil(2.1)` rounds the number up to 3.
Answer: C) Math.floor()
Explanation: `Math.floor()` always rounds a number down to the nearest integer.
Answer: B) 8
Explanation: Since 7.5 is halfway, `Math.round()` rounds it up to 8.
Answer: B) 4
Explanation: `Math.ceil(4.0)` returns 4 since it's already an integer.
Answer: C) Math.round()
Explanation: `Math.round()` rounds to the nearest integer, so it can round up or down depending on the decimal part.
Answer: B) A number between 0 and 1 (excluding 1)
Explanation: `Math.random()` returns a floating-point, pseudo-random number in the range [0, 1), meaning it can be 0 but never exactly 1.
Answer: B) Math.floor(Math.random() * 10)
Explanation: `Math.floor(Math.random() * 10)` gives integers from 0 to 9 by removing the decimal part after multiplying.
Answer: B) A number between 1 and 6
Explanation: This simulates a 6-sided dice roll by shifting the 0β5 result range to 1β6.
Answer: C) To convert the float into an integer
Explanation: `Math.floor()` removes the decimal portion, giving a whole number.
Answer: D) 0 (inclusive) to less than 10
Explanation: `Math.random()` generates a value from 0 up to, but not including, 1. Multiplied by 10, the range is 0 to just below 10.
Answer: C) Math.floor(Math.random() * 6) + 5
Explanation: This gives numbers from 0 to 5, then adds 5, resulting in 5 to 10.
Answer: B) No
Explanation: The maximum possible value is less than 1; `Math.random()` never returns exactly 1.
Answer: C) 6
Explanation: The number 6 sets the size of the range (0 to 5), and +1 shifts it to 1 to 6.
Answer: D) Math.floor(Math.random() * 6) + 1
Explanation: This generates integers from 1 to 6, mimicking a dice roll.
Answer: C) To create unpredictable outcomes
Explanation: Random values help simulate unpredictability, useful for games, simulations, and more.
Answer: A) parseInt()
Explanation: `parseInt()` converts a string to an integer. It ignores any non-numeric characters after the number.
Answer: B) Converts a string into a decimal (floating-point number)
Explanation: `parseFloat()` converts a string to a floating-point number. It reads until it encounters a non-numeric character.
Answer: A) 123
Explanation: `parseInt()` parses the string from left to right and stops parsing when it encounters a non-numeric character, returning the number parsed so far.
Answer: D) All of the above
Explanation: `parseInt()`, `parseFloat()`, and `Number()` all can convert a string to a number, depending on the type (integer or floating-point).
Answer: C) 123.45
Explanation: `Number()` converts the string to a floating-point number, so the output is 123.45.
Answer: A) 10
Explanation: `parseInt()` returns only the integer part of the string, ignoring the decimal part, so it returns 10.
Answer: B) NaN
Explanation: `parseInt()` cannot parse a string that starts with non-numeric characters, so it returns NaN (Not-a-Number).
Answer: A) It stops parsing and returns the number
Explanation: `parseFloat()` reads a string until it hits a non-numeric character, and returns the number parsed so far.
Answer: D) All of the above
Explanation: All methods (`parseInt()`, `parseFloat()`, and `Number()`) can convert the string "42" to an integer, but `parseInt()` is typically used when you expect an integer.
Answer: D) Both B and C
Explanation: `Number()` converts a string to a floating-point number, and returns NaN if the string contains non-numeric characters.
Answer: B) "123"
Explanation: `String()` converts a number to its string representation, so 123 becomes "123".
Answer: D) Using both parseInt() and parseFloat()
Explanation: `parseInt()` and `parseFloat()` are used to convert strings to numbers depending on whether you want an integer or a floating-point number.
Answer: B) Converts a string to a number
Explanation: `Number()` converts a string to a numeric value, either an integer or a floating-point number.
Answer: B) 123.45
Explanation: `Number("123.45")` converts the string to a floating-point number 123.45.
Answer: D) Both B and C
Explanation: Both `parseFloat()` and `Number()` can convert a string to a number with decimals.
Answer: B) "123.45"
Explanation: `String()` converts the number to a string representation, so 123.45 becomes "123.45".
Answer: A) 123
Explanation: `parseInt()` extracts the integer part of the string, so it returns 123.
Answer: B) It returns NaN
Explanation: `Number()` returns NaN (Not-a-Number) if the string cannot be converted to a numeric value.
Answer: B) NaN
Explanation: `Number("123abc")` returns NaN because the string contains non-numeric characters.
Answer: B) Converts a number to a string
Explanation: `String()` converts any value, including numbers and booleans, to a string.
Answer: B) 1.23
Explanation: `toFixed(2)` rounds the number to two decimal places, returning "1.23".
Answer: B) A string representation of a number
Explanation: `toFixed()` returns a string representing the number in fixed-point notation with the specified number of decimals.
Answer: C) Both A and B
Explanation: Both `toFixed()` and `toPrecision()` can be used to control the number of decimal places.
Answer: A) 5.679
Explanation: `toFixed(3)` rounds the number to 3 decimal places, returning "5.679".
Answer: A) Rounds a number to the specified number of significant digits
Explanation: `toPrecision()` formats a number to a specified number of significant digits, not just decimal places.
Answer: A) 10.6
Explanation: `toFixed(1)` rounds the number to 1 decimal place, so the result is "10.6".
Answer: A) Using Math.round()
Explanation: `Math.round()` rounds a number to the nearest integer.
Answer: C) 123.46
Explanation: `toFixed(2)` rounds the number to two decimal places, so the result is "123.46".
Answer: A) The number is padded with zeros
Explanation: If the specified decimal places are more than the number of decimals in the number, `toFixed()` will pad the result with zeros.
C) The number as a string with no decimal points
Explanation: When set to 0 decimal places, `toFixed()` converts
the number as a string with no decimal points