Web Programming JavaScript Programming 1 — Questions and Answers
Question 1: Which JavaScript method is used to add an element to the end of an array?
- append()
- push() (Correct answer)
- add()
- insert()
Correct answer: push()
The push() method adds one or more elements to the end of an array and returns the new length of the array.
Question 2: What does the === operator check in JavaScript?
- Value equality only
- Type equality only
- Both value and type equality (Correct answer)
- Reference equality
Correct answer: Both value and type equality
The strict equality operator === checks that both the value and the data type of two operands are identical, without type coercion.
Question 3: Which keyword is used to declare a block-scoped variable in modern JavaScript?
- var
- let (Correct answer)
- def
- local
Correct answer: let
The let keyword declares a block-scoped variable that is limited to the block, statement, or expression in which it is used.
Question 4: What does JSON stand for?
- JavaScript Object Notation (Correct answer)
- JavaScript Online Network
- Java Serialized Object Notation
- JavaScript Output Node
Correct answer: JavaScript Object Notation
JSON stands for JavaScript Object Notation, a lightweight text-based data interchange format derived from JavaScript object syntax.
Question 5: Which JavaScript method converts a JSON string into a JavaScript object?
- JSON.stringify()
- JSON.parse() (Correct answer)
- JSON.convert()
- JSON.decode()
Correct answer: JSON.parse()
JSON.parse() takes a JSON-formatted string as input and returns the corresponding JavaScript object, array, or value.
Question 6: What is the output of typeof null in JavaScript?
- 'null'
- 'undefined'
- 'object' (Correct answer)
- 'boolean'
Correct answer: 'object'
typeof null returns 'object', which is a well-known bug in JavaScript that has been retained for backward compatibility.
Which JavaScript method is used to add an element to the end of an array?