Basic Java Script Multiple chice question | Javascript Quiz

Are you ready to take your coding skills to the next level? This fundamental JavaScript quiz will test your knowledge of variables, data types, loops, functions, and more. With multiple-choice questions and practical code examples, you'll have fun while learning and challenging yourself.


Master the basics of JavaScript and unlock the power to create amazing web applications!

 

Mastering the Fundamentals of JavaScript

Lets try It

Question of


Exploration

What is the correct way to declare a variable in JavaScript?

A) `variable x = 5;`

B) `var x = 5;`

C) `x = 5;`

D) `let x = 5;`

Answer: B) `var x = 5;`


javascript: var x = 5;

Which function is used to output data to the console in JavaScript?

A) `print()`

B) `console.log()`

C) `output()`

D) `display()`

Answer: B) `console.log()`


javascript: console.log("Hello, world!");

What does the `===` operator do in JavaScript?

A) Assigns a value to a variable

B) Checks for strict equality

C) Checks for inequality

D) Converts a value to a string

Answer: B) Checks for strict equality


javascript
let x = 5;
let y = "5";
console.log(x === y); // Outputs: false
```

Which symbol is used for single-line comments in JavaScript?

A) `//`

B) `/* */`

C) ``

D) `#`

Answer: A) `//`


```javascript
// This is a single-line comment
```

What is the purpose of `typeof` operator in JavaScript?

A) To check if a variable is undefined

B) To return the data type of a value

C) To convert a string to a number

D) To perform arithmetic operations

Answer: B) To return the data type of a value


```javascript
let x = 10;
console.log(typeof x); // Outputs: "number"
```

How do you write an IF statement in JavaScript?

A) `if x = 5 then`

B) `if (x === 5)`

C) `if x === 5`

D) `if x = 5`

Answer: B) `if (x === 5)`


```javascript
let x = 5;
if (x === 5) {
// Code to execute if x is equal to 5
}
```

Which keyword is used to declare a constant variable in JavaScript?

A) `let`

B) `var`

C) `const`

D) `static`

Answer: C) `const`


```javascript
const PI = 3.14;
```

What does the `Array.push()` method do in JavaScript?

A) Removes an element from the end of an array

B) Adds a new element to the end of an array

C) Removes the first element of an array

D) Reverses the order of elements in an array

Answer: B) Adds a new element to the end of an array


```javascript
let fruits = ["apple", "orange"];
fruits.push("banana");
console.log(fruits); // Outputs: ["apple", "orange", "banana"]
```

How do you access the third element in an array named `numbers`?

A) `numbers[3]`

B) `numbers.third()`

C) `numbers[2]`

D) `numbers.get(3)`

Answer: C) `numbers[2]`


```javascript
let numbers = [1, 2, 3, 4, 5];
console.log(numbers[2]); // Outputs: 3
```

What does the `NaN` stand for in JavaScript?

A) Not a Null

B) Null or Negative

C) Not a Number

D) Negative And Null

Answer: C) Not a Number


```javascript
console.log(isNaN("Hello")); // Outputs: true
```

Which method is used to remove the last element from an array in JavaScript?

A) `removeLast()`

B) `pop()`

C) `deleteLast()`

D) `spliceLast()`

Answer: B) `pop()


```javascript
let fruits = ["apple", "orange", "banana"];
fruits.pop();
console.log(fruits); // Outputs: ["apple", "orange"]
```

What is the purpose of the `forEach()` method in JavaScript?

A) Executes a function once for each array element

B) Sorts the array elements in descending order

C) Finds the maximum element in the array

D) Removes specific elements from the array

Answer: A) Executes a function once for each array element


```javascript
let numbers = [1, 2, 3];
numbers.forEach(function(number) {
console.log(number);
});
// Outputs:
// 1
// 2
// 3

Which function is used to convert a string to an integer in JavaScript?

A) `int()`

B) `convertToInt()`

C) `parseInt()`

D) `toInteger()`

Answer: C) `parseInt()`


```javascript
let num = parseInt("10");
console.log(num); // Outputs: 10
```

What does the `charAt()` method return in JavaScript?

A) Returns the character at a specified index

B) Returns the length of a string

C) Checks if a character is present in a string

D) Converts a string to uppercase

Answer: A) Returns the character at a specified index


```javascript
let str = "Hello";
console.log(str.charAt(1)); // Outputs: "e"
```

Which loop is used for executing a block of code a specified number of times in JavaScript?

A) `do...while` loop

B) `for` loop

C) `while` loop

D) `switch` loop

Answer: B) `for` loop


```javascript
for (let i = 0; i< 5; i++) {
// Code to execute
}
```

What does the `substring()` method do in JavaScript?

A) Removes whitespace from both ends of a string

B) Returns the characters between two specified indices

C) Replaces characters in a string with another character

D) Checks if a string contains another string

Answer: B) Returns the characters between two specified indices


```javascript
let str = "Hello, World!";
console.log(str.substring(7, 12)); // Outputs: "World"
```

Which operator is used to combine two strings in JavaScript?

A) `+`

B) `&`

C) `*`

D) `++`

Answer: A) `+`


```javascript
let str1 = "Hello";
let str2 = "World";
let combined = str1 + " " + str2;
console.log(combined); // Outputs: "Hello World"
```

What is the purpose of the `Math.random()` method in JavaScript?

A) Returns a random number between 0 and 1

B) Generates a random string

C) Rounds a number to the nearest integer

D) Calculates the square root of a number

Answer: A) Returns a random number between 0 and 1


```javascript
let randomNumber = Math.random();
console.log(randomNumber); // Outputs a random number between 0 and 1
```

Which function is used to find the length of an array in JavaScript?

A) `array.length()`

B) `array.size()`

C) `array.count()`

D) `array.length`

Answer: D) `array.length`


```javascript
let fruits = ["apple", "orange", "banana"];
console.log(fruits.length); // Outputs: 3
```

What does the `toFixed()` method do in JavaScript?

A) Converts a number to a fixed string

B) Rounds a number to the nearest integer

C) Converts a number to a string, keeping a specified number of decimals

D) Trims leading and trailing whitespace from a string

Answer: C) Converts a number to a string, keeping a specified number of decimals


```javascript
let num = 10.56789;
console.log(num.toFixed(2)); // Outputs: "10.57"
```

This quiz covered JavaScript Fundamentals, from basic to more advanced . Each multiple choice question is followed by a detailed explanation and Code of the correct answer, providing learners with valuable insights into the application's capabilities and functionalities.

Pleas Support Me QuizoNext.

Good!

You Got Question Correct
out of Question's



Is Your Total Score

Post a Comment

1 Comments