JavaScript JSON

Last Updated :
Discuss
Comments

Question 1

What is the purpose of the search() method in strings?

  • A

    Returns an array of matches

  • B

    Finds the index of the first match

  • C

    Validates a regular expression pattern

  • D

    Replaces the first match with a new string

Question 2

What does the i flag in a regular expression do?

  • A

    Makes the search case-insensitive

  • B

    Searches for all matches globally

  • C

    Stops the search after the first match

  • D

    Allows the use of groups in the regular expression

Question 3

Which method converts a JSON string into a JavaScript object?

  • A

    JSON.stringify()

  • B

    JSON.parse()

  • C

    JSON.format()

  • D

    JSON.validate()

Question 4

What will the following code output?

JavaScript
const obj = { name: "Ajay", age: 25 };
console.log(JSON.stringify(obj));


  • A

    undefined

  • B

    { name: "Ajay", age: 25 }

  • C

    '{"name":"Ajay","age":25}'

  • D

    Error

Question 5

Which of the following is a valid JSON structure?

  • A

    { "name": "Ajay", "age": 25 }

  • B

    { name: "Ajay", age: 25 }

  • C

    [name: "Ajay", age: 25]

  • D

    { name: "Ajay", age: "25" }

Question 6

What will the following code log?

JavaScript
const obj = { name: "Ajay", age: 30 };
const json = JSON.stringify(obj);
console.log(JSON.parse(json).age);


  • A

    undefined

  • B

    30

  • C

    Error

  • D

    null

Question 7

Which method can convert a JavaScript object to a readable JSON string?

  • A

    JSON.format()

  • B

    JSON.validate()

  • C

    JSON.stringify()

  • D

    JSON.parse()

Question 8

What is the key difference between JSON and JavaScript objects?

  • A

    JSON allows functions as values.

  • B

    JSON keys can be unquoted.

  • C

    JSON can include circular references.

  • D

    JSON requires double-quoted keys and string values.

Question 9

What will the following code log?

JavaScript
const json = '[{"id":1},{"id":2}]';
console.log(JSON.parse(json)[0].id);


  • A

    Error

  • B

    undefined

  • C

    1

  • D

    null

Question 10

What does JSON.parse() do?

  • A

    Converts a JavaScript object to a JSON string

  • B

    Parses a JSON string into a JavaScript object

  • C

    Formats a JSON string for readability

  • D

    Validates a JSON string

There are 10 questions to complete.

Take a part in the ongoing discussion