JavaScript Strings, Numbers, and Dates Quiz Quiz

  1. String length property

    What is the result of 'JavaScript'.length?

    1. 8
    2. 10
    3. 9
    4. 12
    5. 11
  2. Finding character position in a string

    Which method returns the index of the first occurrence of 'a' in the string 'banana'?

    1. charAt
    2. locate
    3. indexOf
    4. getIndex
    5. findChar
  3. Changing string case

    What does 'hello world'.toUpperCase() return?

    1. Hello world
    2. Hello_world
    3. hello world
    4. Hello World
    5. HELLO WORLD
  4. Checking substring presence

    Which method checks if 'fun' exists within the string 'Have fun coding'?

    1. includes
    2. inString
    3. test
    4. find
    5. hasString
  5. Extracting part of a string

    What method would you use to extract 'Script' from 'JavaScript'?

    1. substring
    2. parse
    3. extract
    4. explode
    5. split
  6. Template literals

    What will be the output of `The answer is ${6 + 4}` using template literals?

    1. The answer is ${6+4}
    2. The answer is 64
    3. The answer is six plus four
    4. The answer is {6+4}
    5. The answer is 10
  7. Creating numbers from strings

    Which method will convert the string '123' into a number?

    1. parseChar
    2. stringToNum
    3. Number
    4. numValue
    5. toDigit
  8. Number to fixed decimals

    What does (3.14159).toFixed(2) return?

    1. 3.141
    2. 3.14
    3. 3
    4. 3.1
    5. 3.142
  9. NaN explanation

    What does 'NaN' stand for in JavaScript?

    1. Number as Null
    2. Null at Number
    3. New as Needed
    4. Not a Number
    5. Negative and Null
  10. Absolute values

    Which Math object method returns the positive value of a number, such as Math.abs(-5)?

    1. Math.value
    2. Math.abs
    3. Math.absolute
    4. Math.absval
    5. Math.positive
  11. Rounding numbers

    Which Math method rounds 5.7 up to the nearest integer?

    1. Math.up
    2. Math.round
    3. Math.trunc
    4. Math.floor
    5. Math.ceil
  12. Random number generation

    What does Math.random() produce in JavaScript?

    1. A random negative number
    2. A random integer between 0 and 100
    3. A random floating-point number between 0 (inclusive) and 1 (exclusive)
    4. A random decimal from 1 to 10
    5. A random boolean value
  13. Getting the current date

    Which code creates a Date object representing the current date and time?

    1. createDate()
    2. getDate()
    3. new Date()
    4. Date.now()
    5. Date.today()
  14. Extracting year from Date object

    Given a Date object 'now', which method retrieves the full year (e.g., 2024)?

    1. getDateYear
    2. getYear
    3. fetchYear
    4. fullYear
    5. getFullYear
  15. String trimming

    What does the 'trim()' method do to a string such as ' hello '?

    1. Converts text to lowercase
    2. Removes all spaces
    3. Extracts the first word
    4. Removes whitespace from both ends
    5. Joins strings together