JavaScript Advanced Concepts Challenge — Questions & Answers

Test your expertise on advanced JavaScript topics including Regular Expressions, JSON, AJAX, Fetch API, Geolocation, Web Storage, and Canvas functionality. This quiz aims to assess your deep understanding through complex scenarios and code analysis.

This quiz contains 15 questions. Below is a complete reference of all questions, answer choices, and correct answers. You can use this section to review after taking the interactive quiz above.

  1. Question 1: Regular Expression Question 1

    Which regular expression will correctly match a string that starts with a digit, followed by exactly four lowercase letters and ends with a period?

    • ^\d[a-z]{4}\.$
    • ^[0-9][A-Z]{4}\.$
    • ^\d[a-z]{4}\.*$
    • ^\d[a-z]{5}\.$
    • ^\d+\w{4}\.$
    Show correct answer

    Correct answer: ^\d[a-z]{4}\.$

  2. Question 2: JSON Parsing Question 2

    Given a valid JSON string stored in the variable data, which method would you use in JavaScript to convert it into an object?

    • JSON.read(data)
    • JSON.parse(data)
    • JSON.decode(data)
    • objectify(data)
    • parseJSON(data)
    Show correct answer

    Correct answer: JSON.parse(data)

  3. Question 3: Regular Expression Groups Question 3

    Which return type is produced by calling str.match(/(foo)(bar)/) where str is 'foobarfoo'?

    • String containing just 'foobar'
    • Boolean true or false
    • Array with full match and capture groups
    • Object with properties full and groups
    • Only the first index of matched string
    Show correct answer

    Correct answer: Array with full match and capture groups

  4. Question 4: JSON Stringify Question 4

    If you run JSON.stringify({name: 'Ana', greet: function() { return 'hi'; }}) in JavaScript, what will be the output?

    • {}
    • {"name":"Ana","greet":null}
    • {"name":"Ana","greet":"function() { return 'hi'; }"}
    • TypeError thrown at runtime
    • {"name":"Ana"}
    Show correct answer

    Correct answer: {"name":"Ana"}

  5. Question 5: AJAX Request Ready State Question 5

    In an XMLHttpRequest, what is the value of readyState when the request has been sent but response is not yet available?

    • 1
    • 3
    • 4
    • 0
    • 2
    Show correct answer

    Correct answer: 2

  6. Question 6: Fetch API Error Handling Question 6

    When using fetch() in JavaScript, which statement correctly processes the response only if the server returns a successful status code?

    • if(response.done) { /* handle success */ }
    • if(response.ok) { /* handle success */ }
    • if(response.success) { /* handle success */ }
    • if(response.statusText === 'OK') { /* handle success */ }
    • if(response.complete) { /* handle success */ }
    Show correct answer

    Correct answer: if(response.ok) { /* handle success */ }

  7. Question 7: Geolocation API Question 7

    Which method of the Geolocation API is used to continuously receive location updates as the user's position changes?

    • watchPosition()
    • trackPosition()
    • listenPosition()
    • monitorPosition()
    • getLivePosition()
    Show correct answer

    Correct answer: watchPosition()

  8. Question 8: Web Storage Capacity Question 8

    Approximately how much data (in megabytes) can you typically store per domain using localStorage in most modern web browsers?

    • 50 MB
    • 100 MB
    • 1 GB
    • 5 MB
    • 512 KB
    Show correct answer

    Correct answer: 5 MB

  9. Question 9: Session Storage Question 9

    What differentiates sessionStorage from localStorage in the Web Storage API?

    • sessionStorage handles only numeric values
    • sessionStorage requires user permission prompt
    • sessionStorage encrypts data by default
    • sessionStorage can be accessed from all open tabs
    • sessionStorage data persists only for the duration of the page session
    Show correct answer

    Correct answer: sessionStorage data persists only for the duration of the page session

  10. Question 10: AJAX Response Type Question 10

    Which responseType property value should you set on XMLHttpRequest to handle binary image data as a Blob?

    • text
    • stream
    • document
    • blob
    • arraybuffer
    Show correct answer

    Correct answer: blob

  11. Question 11: Canvas Drawing Question 11

    What method draws a filled rectangle at position (30,50) with a width of 150 and height 40 on a canvas context ctx?

    • ctx.rectFill(150, 40, 30, 50)
    • ctx.rectangle(30, 50, 150, 40)
    • ctx.fillRect(30, 50, 150, 40)
    • ctx.strokeRect(30, 50, 150, 40)
    • ctx.drawRect(30, 50, 150, 40)
    Show correct answer

    Correct answer: ctx.fillRect(30, 50, 150, 40)

  12. Question 12: Fetch API Content-Type Question 12

    When making a POST request with fetch to send JSON data, which header is essential to inform the server of the data format?

    • Data-Type: JSON
    • Accept-Language: en-US
    • X-Requested-With: XMLHttpRequest
    • Content-Type: application/json
    • Content-Length: application/json
    Show correct answer

    Correct answer: Content-Type: application/json

  13. Question 13: Regular Expressions Lookahead Question 13

    In regular expressions, which construct will match 'cat' only if it is not followed by 'fish'?

    • cat(?=fish)
    • cat[^fish]
    • cat(?!fish)
    • cat(?<fish)
    • cat|fish
    Show correct answer

    Correct answer: cat(?!fish)

  14. Question 14: Canvas Image Manipulation Question 14

    How would you draw an image object img onto ctx at coordinates (0,0) with width 200 and height 100?

    • ctx.putImageData(img, 0, 0, 200, 100)
    • ctx.renderImage(img, 0, 0, 200, 100)
    • ctx.imageDraw(img, 0, 0, 200, 100)
    • ctx.drawImage(img, 0, 0, 200, 100)
    • img.drawTo(ctx, 0, 0, 200, 100)
    Show correct answer

    Correct answer: ctx.drawImage(img, 0, 0, 200, 100)

  15. Question 15: JSON Limitations Question 15

    Which type of property will be omitted when using JSON.stringify on an object in JavaScript?

    • A function property
    • A numeric property
    • A boolean property
    • A string property
    • A null property
    Show correct answer

    Correct answer: A function property