Multiple Choice Question for Grand JS Quiz



(Chap # 21 - Changing Case )

(1) What does the method `toUpperCase()` do in JavaScript?

A) Changes all characters to lowercase
B) Removes all spaces
C) Changes all characters to uppercase
D) Capitalizes only the first letter

Answer: C) Changes all characters to uppercase

Explanation: The `toUpperCase()` method converts all alphabetic characters in a string to uppercase.



(2) What will `"hello".toUpperCase()` return?

A) Hello
B) HELLO
C) hello
D) hELLO

Answer: B) HELLO

Explanation: All letters are converted to uppercase, so `"hello"` becomes `"HELLO"`.



(3) Which method would you use to convert "GOODBYE" to "goodbye"?

A) toLowerCase()
B) toUpperCase()
C) toCapitalize()
D) toString()

Answer: A) toLowerCase()

Explanation: The `toLowerCase()` method converts a string to all lowercase letters.



(4) What is the result of this code?

var city = "Karachi";
alert(city.toLowerCase());


A) karachi
B) Karachi
C) KARACHI
D) error

Answer: A) karachi

Explanation: The `toLowerCase()` method converts `"Karachi"` to `"karachi"`.



(5) What happens if you use `toUpperCase()` on a string that is already uppercase?

A) It causes an error
B) It returns the string unchanged
C) It converts to lowercase
D) It trims spaces

Answer: B) It returns the string unchanged

Explanation: Since the string is already uppercase, `toUpperCase()` returns it as is.



(6) Which line correctly converts the value of `name = "ali"` to "ALI"?

A) name.toUpperCase();
B) name.toUpperCase;
C) toUpperCase(name);
D) upper(name);

Answer: A) name.toUpperCase();

Explanation: The correct syntax is to call the method on the string using dot notation and parentheses.



(7) What will `"JavaScript".toLowerCase()` output?

A) javascript
B) JAVASCRIPT
C) JavaScript
D) Error

Answer: A) javascript

Explanation: `toLowerCase()` converts all characters in the string to lowercase.



(8) How do you store the lowercase version of a string?

A) string.toLowerCase;
B) var newStr = toLowerCase(string);
C) var newStr = string.toLowerCase();
D) string.lower();

Answer: C) var newStr = string.toLowerCase();

Explanation: This is the correct way to store the result of the `toLowerCase()` method in a variable.



(9) What will be the output?

var word = "WOW";
alert(word.toLowerCase());


A) wow
B) WOW
C) WoW
D) Error

Answer: A) wow

Explanation: The method `toLowerCase()` changes "WOW" to "wow".



(10) What is the purpose of changing string case in JavaScript?

A) For mathematical operations
B) For styling in CSS
C) For consistent comparison or display
D) To delete data

Answer: C) For consistent comparison or display

Explanation: Changing case helps ensure strings match consistently when comparing or displaying text.



(Chap # 22 - Measuring Length and Extracting Parts )

(1) What does the `length` property return for a string?

A) The number of words
B) The number of characters
C) The number of spaces
D) The memory size

Answer: B) The number of characters

Explanation: The `length` property gives the total number of characters in a string, including spaces and punctuation.



(2) What will `"hello".length` return?

A) 4
B) 5
C) 6
D) 0

Answer: B) 5

Explanation: The string "hello" has 5 characters, so `.length` returns 5.



(3) What does `slice()` do in JavaScript?

A) Cuts the string in half
B) Replaces part of a string
C) Extracts a part of the string and returns it
D) Converts string to uppercase

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.



(4) What is the result of this code?

var text = "JavaScript";
alert(text.slice(0, 4));


A) Java
B) Script
C) JavaScript
D) avaS

Answer: A) Java

Explanation: `slice(0, 4)` extracts characters from index 0 up to, but not including, index 4.



(5) What will `"world".slice(1, 4)` return?

A) wor
B) orl
C) or
D) orl

Answer: D) orl

Explanation: Characters from index 1 to index 3 are returned: "o", "r", "l".



(6) How can you extract the last 3 characters from a string?

A) string.slice(3)
B) string.slice(-3)
C) string.pop(3)
D) string.shift(3)

Answer: B) string.slice(-3)

Explanation: A negative number in `slice()` counts from the end of the string.



(7) What is the value of:

var msg = "Welcome!";
alert(msg.length);


A) 8
B) 9
C) 7
D) 6

Answer: B) 8

Explanation: The string "Welcome!" has 8 characters including the exclamation mark.



(8) What happens if you use `slice()` with only one parameter?

A) It throws an error
B) It extracts from that index to the end
C) It returns the entire string
D) It deletes part of the string

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.



(9) Which of the following would return the first character of a string `msg`?

A) msg.slice(0, 1)
B) msg.slice(1, 0)
C) msg.length(1)
D) msg.get(0)

Answer: A) msg.slice(0, 1)

Explanation: `slice(0, 1)` returns a substring starting at index 0 and ending before index 1.



(10) Which method is commonly used to get part of a string?

A) split()
B) match()
C) slice()
D) append()

Answer: C) slice()

Explanation: The `slice()` method is widely used to extract parts of a string.



(Chap # 23 - Strings – Finding Segments )

(1) Which method is used to check if a specific substring exists within a string?

A) includes()
B) slice()
C) split()
D) find()

Answer: A) includes()

Explanation: The `includes()` method checks if a string contains a specified substring and returns true or false.



(2) What does the following code return?

"JavaScript".includes("Script")


A) true
B) false
C) Script
D) undefined

Answer: A) true

Explanation: "Script" is a substring of "JavaScript", so `includes()` returns true.



(3) What does the `indexOf()` method do?

A) Extracts part of a string
B) Returns the index of the first match
C) Converts a string to lowercase
D) Replaces part of a string

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.



(4) What is the result of:

"hello world".indexOf("world")


A) 5
B) 6
C) 7
D) -1

Answer: A) 6

Explanation: The word "world" starts at index 6 in the string "hello world".



(5) What does `indexOf()` return when the substring is not found?

A) undefined
B) null
C) -1
D) 0

Answer: C) -1

Explanation: When the substring is not found, `indexOf()` returns -1.



(6) Which method is used to check if a string ends with a specific value?

A) endsWith()
B) includes()
C) match()
D) indexOf()

Answer: A) endsWith()

Explanation: The `endsWith()` method checks if a string ends with the specified value.



(7) What will this code return?

"hello.js".endsWith(".js")


A) false
B) true
C) .js
D) undefined

Answer: B) true

Explanation: The string "hello.js" ends with ".js", so `endsWith()` returns true.



(8) What does the `lastIndexOf()` method do?

A) Returns the length of a string
B) Returns the last character
C) Returns the last index of a specified substring
D) Returns the total number of matches

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.



(9) Which of the following returns true?

var str = "abcabc";
str.lastIndexOf("a") === 3;


A) true
B) false
C) a
D) 1

Answer: A) true

Explanation: The last "a" in "abcabc" is at index 3.



(10) What value does this return?

"test".includes("z")


A) true
B) false
C) undefined
D) z

Answer: B) false

Explanation: Since "z" is not present in "test", `includes()` returns false.



(Chap # 24 - Strings – Finding a Character at a Location )

(1) Which method is used to get the character at a specific index in a string?

A) charAt()
B) character()
C) getChar()
D) at()

Answer: A) charAt()

Explanation: The `charAt()` method returns the character at the specified index in a string.



(2) What will the following code return?

"JavaScript".charAt(4)


A) S
B) c
C) S
D) S

Answer: C) S

Explanation: The character at index 4 in "JavaScript" is "S".



(3) What does `charAt()` return if the index is out of range?

A) null
B) undefined
C) empty string
D) Error

Answer: C) empty string

Explanation: If the index is greater than or equal to the string length, `charAt()` returns an empty string.



(4) What is the output of:

"hello".charAt(0)


A) h
B) e
C) o
D) l

Answer: A) h

Explanation: Index 0 corresponds to the first character, which is "h".



(5) How do you access the last character of a string using `charAt()`?

A) string.charAt(length)
B) string.charAt(-1)
C) string.charAt(string.length - 1)
D) string.charAt()

Answer: C) string.charAt(string.length - 1)

Explanation: The last character is at the index one less than the string’s length.



(6) What will this return?

"abc".charAt(10)


A) c
B) a
C) "" (empty string)
D) undefined

Answer: C) "" (empty string)

Explanation: Index 10 is out of range, so `charAt()` returns an empty string.



(7) Which method is more modern and can be used as an alternative to `charAt()`?

A) charIndex()
B) at()
C) getChar()
D) slice()

Answer: B) at()

Explanation: The `at()` method is a modern alternative that can also take negative indexes.



(8) What does this return?

"hello".at(-1)


A) o
B) h
C) l
D) Error

Answer: A) o

Explanation: Negative index -1 refers to the last character using the `at()` method.



(9) What will be the output of:

var word = "OpenAI";
alert(word.charAt(2));


A) p
B) e
C) e
D) n

Answer: C) e

Explanation: Index 2 in "OpenAI" is the letter "e".



(10) What will `charAt()` return if the index is not provided?

A) The first character
B) undefined
C) null
D) Error

Answer: A) The first character

Explanation: If no index is given, `charAt()` treats it as 0 and returns the first character.



(Chap # 25 - Strings – Replacing Characters )

(1) Which method is used to replace characters in a string?

A) replaceText()
B) change()
C) replace()
D) modify()

Answer: C) replace()

Explanation: The `replace()` method is used in JavaScript to replace part of a string with another value.



(2) What will this code return?

"I like apples".replace("apples", "bananas")


A) I like bananas
B) I like apples
C) bananas like I
D) Error

Answer: A) I like bananas

Explanation: The `replace()` method substitutes "apples" with "bananas" in the original string.



(3) What does the replace() method affect?

A) The original string
B) A new string
C) Both
D) None

Answer: B) A new string

Explanation: Strings are immutable in JavaScript; `replace()` returns a new string without modifying the original.



(4) Which value does `replace()` affect if multiple matches are found?

A) All matches
B) Last match
C) First match only
D) None

Answer: C) First match only

Explanation: By default, `replace()` replaces only the first occurrence unless a global regex is used.



(5) How can you replace all instances of a word in a string?

A) Use `replaceAll()`
B) Use `replace()` with global regex
C) Both A and B
D) You cannot

Answer: C) Both A and B

Explanation: You can use `replaceAll()` or `replace()` with a global regular expression like /word/g.



(6) What will be the result of:

"dog dog dog".replace(/dog/g, "cat")


A) dog cat dog
B) cat cat cat
C) dog dog dog
D) Error

Answer: B) cat cat cat

Explanation: The global regex `/dog/g` replaces all occurrences of "dog" with "cat".



(7) What will this return?

"Hello, World!".replace("World", "Universe")


A) Hello, Universe!
B) Hello, World!
C) Universe, Hello!
D) Error

Answer: A) Hello, Universe!

Explanation: "World" is replaced by "Universe" using the `replace()` method.



(8) What will the following code output?

var str = "one two three";
alert(str.replace("two", "2"));


A) one 2 three
B) one two 3
C) one two three
D) 2 two three

Answer: A) one 2 three

Explanation: The word "two" is replaced with "2" in the original string.



(9) Which of the following will replace all "a" with "x"?

A) str.replace("a", "x")
B) str.replace(/a/g, "x")
C) str.replaceAll("a", "x")
D) Both B and C

Answer: D) Both B and C

Explanation: Both `replaceAll()` and `replace()` with global regex can replace all occurrences of "a".



(10) Is it possible to chain `replace()` calls?

A) Yes
B) No
C) Only with `replaceAll()`
D) Only with regex

Answer: A) Yes

Explanation: You can chain `replace()` methods to apply multiple replacements in a single expression.



(Chap # 26 - Rounding Numbers )

(1) Which method rounds a number to the nearest integer?

A) Math.round()
B) Math.floor()
C) Math.ceil()
D) Math.nearest()

Answer: A) Math.round()

Explanation: `Math.round()` returns the value of a number rounded to the nearest integer.



(2) What is the result of Math.round(4.7)?

A) 4
B) 5
C) 4.7
D) 6

Answer: B) 5

Explanation: 4.7 is closer to 5, so `Math.round()` returns 5.



(3) What does Math.floor() do?

A) Rounds to nearest integer
B) Rounds up
C) Rounds down
D) Returns a decimal

Answer: C) Rounds down

Explanation: `Math.floor()` always rounds a number downward to the nearest whole number.



(4) What is the output of Math.floor(9.8)?

A) 10
B) 9.8
C) 9
D) 8

Answer: C) 9

Explanation: `Math.floor(9.8)` rounds the value down to 9.



(5) What is the purpose of Math.ceil()?

A) Rounds down
B) Rounds to nearest
C) Rounds up
D) Makes a ceiling

Answer: C) Rounds up

Explanation: `Math.ceil()` always rounds a number upward to the next largest integer.



(6) What does Math.ceil(2.1) return?

A) 2
B) 3
C) 2.1
D) 1

Answer: B) 3

Explanation: `Math.ceil(2.1)` rounds the number up to 3.



(7) Which method would you use to always round down decimal values?

A) Math.round()
B) Math.ceil()
C) Math.floor()
D) Math.down()

Answer: C) Math.floor()

Explanation: `Math.floor()` always rounds a number down to the nearest integer.



(8) What is the output of Math.round(7.5)?

A) 7
B) 8
C) 7.5
D) 6

Answer: B) 8

Explanation: Since 7.5 is halfway, `Math.round()` rounds it up to 8.



(9) What will Math.ceil(4.0) return?

A) 5
B) 4
C) 4.0
D) Error

Answer: B) 4

Explanation: `Math.ceil(4.0)` returns 4 since it's already an integer.



(10) Which of the following can round a number both up and down?

A) Math.floor()
B) Math.ceil()
C) Math.round()
D) None

Answer: C) Math.round()

Explanation: `Math.round()` rounds to the nearest integer, so it can round up or down depending on the decimal part.



(Chap # 27 - Generating Random Numbers )

(1) What does Math.random() return?

A) A random integer
B) A number between 0 and 1 (excluding 1)
C) A number between 1 and 10
D) An undefined value

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.



(2) Which expression gives a random integer from 0 to 9?

A) Math.random() * 10
B) Math.floor(Math.random() * 10)
C) Math.round(Math.random() * 10)
D) Math.ceil(Math.random() * 10)

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.



(3) What does this expression return: Math.floor(Math.random() * 6) + 1?

A) A number between 0 and 5
B) A number between 1 and 6
C) A number between 1 and 5
D) A number between 0 and 6

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.



(4) Why do we use Math.floor with Math.random()?

A) To round the number up
B) To generate decimals
C) To convert the float into an integer
D) To make the number larger

Answer: C) To convert the float into an integer

Explanation: `Math.floor()` removes the decimal portion, giving a whole number.



(5) What is the range of numbers returned by Math.random() * 10?

A) 0 to 10 (inclusive)
B) 1 to 10
C) 0 to 9
D) 0 (inclusive) to less than 10

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.



(6) How would you generate a random number between 5 and 10 (inclusive)?

A) Math.random() * 5 + 5
B) Math.floor(Math.random() * 5) + 5
C) Math.floor(Math.random() * 6) + 5
D) Math.floor(Math.random() * 10) + 1

Answer: C) Math.floor(Math.random() * 6) + 5

Explanation: This gives numbers from 0 to 5, then adds 5, resulting in 5 to 10.



(7) Can Math.random() ever return exactly 1?

A) Yes
B) No
C) Only in some browsers
D) Only if rounded

Answer: B) No

Explanation: The maximum possible value is less than 1; `Math.random()` never returns exactly 1.



(8) Which part of this expression defines the range size? Math.floor(Math.random() * 6) + 1

A) Math.floor()
B) Math.random()
C) 6
D) + 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.



(9) Which method is used to simulate a dice roll in JavaScript?

A) Math.floor(Math.random() * 6)
B) Math.random() * 6
C) Math.round(Math.random() * 6)
D) Math.floor(Math.random() * 6) + 1

Answer: D) Math.floor(Math.random() * 6) + 1

Explanation: This generates integers from 1 to 6, mimicking a dice roll.



(10) What is the main use of Math.random() in games or simulations?

A) To generate dates
B) To control CSS
C) To create unpredictable outcomes
D) To store data

Answer: C) To create unpredictable outcomes

Explanation: Random values help simulate unpredictability, useful for games, simulations, and more.



(Chap # 28 - Converting strings to integers and decimals )

(1) Which method is used to convert a string to an integer?

A) parseInt()
B) parseFloat()
C) toString()
D) Number()

Answer: A) parseInt()

Explanation: `parseInt()` converts a string to an integer. It ignores any non-numeric characters after the number.



(2) What does parseFloat() do?

A) Converts a string into an integer
B) Converts a string into a decimal (floating-point number)
C) Rounds a string value to the nearest integer
D) Converts a string into a boolean

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.



(3) What will the following code return: parseInt("123abc")?

A) 123
B) NaN
C) 0
D) Error

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.



(4) Which method can be used to convert a string to a number (either integer or decimal)?

A) parseInt()
B) parseFloat()
C) Number()
D) All of the above

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).



(5) What is the output of Number("123.45")?

A) 123
B) "123.45"
C) 123.45
D) NaN

Answer: C) 123.45

Explanation: `Number()` converts the string to a floating-point number, so the output is 123.45.



(6) What does parseInt("10.5") return?

A) 10
B) 10.5
C) NaN
D) Error

Answer: A) 10

Explanation: `parseInt()` returns only the integer part of the string, ignoring the decimal part, so it returns 10.



(7) What will parseInt("abc123") return?

A) 0
B) NaN
C) 123
D) Error

Answer: B) NaN

Explanation: `parseInt()` cannot parse a string that starts with non-numeric characters, so it returns NaN (Not-a-Number).



(8) What happens if parseFloat() encounters non-numeric characters after a number?

A) It stops parsing and returns the number
B) It returns NaN
C) It converts the non-numeric characters to a number
D) It throws an error

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.



(9) Which method would you use to convert a string "42" into an integer?

A) parseInt("42")
B) parseFloat("42")
C) Number("42")
D) All of the above

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.



(10) Which of the following statements is true about Number()?

A) It converts any string with numbers to an integer
B) It converts strings to floating-point numbers
C) It returns NaN if the string contains non-numeric characters
D) Both B and C

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.



(Chap # 29 - Converting strings to numbers, numbers to strings )

(1) What is the result of String(123)?

A) 123
B) "123"
C) 123.0
D) NaN

Answer: B) "123"

Explanation: `String()` converts a number to its string representation, so 123 becomes "123".



(2) How do you convert a string to a number in JavaScript?

A) Using String()
B) Using parseInt()
C) Using parseFloat()
D) Using both parseInt() and parseFloat()

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.



(3) What does the Number() function do?

A) Converts a number to a string
B) Converts a string to a number
C) Rounds a number
D) Parses 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.



(4) What will the following code return: Number("123.45")?

A) 123
B) 123.45
C) "123.45"
D) NaN

Answer: B) 123.45

Explanation: `Number("123.45")` converts the string to a floating-point number 123.45.



(5) Which method would you use to convert a string to a number with decimal places?

A) parseInt()
B) parseFloat()
C) Number()
D) Both B and C

Answer: D) Both B and C

Explanation: Both `parseFloat()` and `Number()` can convert a string to a number with decimals.



(6) What will the following code return: String(123.45)?

A) 123
B) "123.45"
C) 123
D) NaN

Answer: B) "123.45"

Explanation: `String()` converts the number to a string representation, so 123.45 becomes "123.45".



(7) What will parseInt("123.45") return?

A) 123
B) 123.45
C) NaN
D) Error

Answer: A) 123

Explanation: `parseInt()` extracts the integer part of the string, so it returns 123.



(8) What happens when a non-numeric string is passed to the Number() function?

A) It returns 0
B) It returns NaN
C) It returns "NaN"
D) It throws an error

Answer: B) It returns NaN

Explanation: `Number()` returns NaN (Not-a-Number) if the string cannot be converted to a numeric value.



(9) What is the result of Number("123abc")?

A) 123
B) NaN
C) "123abc"
D) 0

Answer: B) NaN

Explanation: `Number("123abc")` returns NaN because the string contains non-numeric characters.



(10) What does the String() function do?

A) Converts a string to a number
B) Converts a number to a string
C) Converts a boolean to a string
D) Converts a string to a boolean

Answer: B) Converts a number to a string

Explanation: `String()` converts any value, including numbers and booleans, to a string.



(Chap # 30 - Controlling the length of decimals! )

(1) What is the output of the following code: (1.2345).toFixed(2)?

A) 1.2345
B) 1.23
C) 1.24
D) 1.000

Answer: B) 1.23

Explanation: `toFixed(2)` rounds the number to two decimal places, returning "1.23".



(2) What does the toFixed() method return?

A) A rounded number
B) A string representation of a number
C) The number without decimals
D) An error

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.



(3) How can you control the number of decimal places when performing a mathematical calculation?

A) Using toFixed()
B) Using toPrecision()
C) Both A and B
D) Neither A nor B

Answer: C) Both A and B

Explanation: Both `toFixed()` and `toPrecision()` can be used to control the number of decimal places.



(4) What is the result of the following code: (5.6789).toFixed(3)?

A) 5.679
B) 5.68
C) 5.678
D) 5.6789

Answer: A) 5.679

Explanation: `toFixed(3)` rounds the number to 3 decimal places, returning "5.679".



(5) What does the `toPrecision()` method do?

A) Rounds a number to the specified number of significant digits
B) Converts a number to an integer
C) Converts a number to a string with specified decimal places
D) Returns a boolean value based on the number

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.



(6) What will (10.5678).toFixed(1) return?

A) 10.6
B) 10.57
C) 10.5678
D) 10.567

Answer: A) 10.6

Explanation: `toFixed(1)` rounds the number to 1 decimal place, so the result is "10.6".



(7) How can you round a number to the nearest integer in JavaScript?

A) Using Math.round()
B) Using toFixed()
C) Using parseInt()
D) Using Math.floor()

Answer: A) Using Math.round()

Explanation: `Math.round()` rounds a number to the nearest integer.



(8) What will the following code output: (123.4567).toFixed(2)?

A) 123.45
B) 123.4567
C) 123.46
D) 123.0

Answer: C) 123.46

Explanation: `toFixed(2)` rounds the number to two decimal places, so the result is "123.46".



(9) What happens if the argument passed to `toFixed()` is larger than the number of decimals in the number?

A) The number is padded with zeros
B) The number is rounded
C) It throws an error
D) It returns the number unchanged

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.



(10) What does `toFixed()` return when the decimal places are set to 0?

A) The integer part of the number
B) The number rounded to the nearest integer as a string
C) The number as a string with no decimal points
D) The same number unchanged

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



βͺ ⏩

Prepared by "Ismail Shah"