menu

JavaScript Basics

JavaScript Basics - Important Points


26. Which of the following is a valid way to declare a variable in JavaScript?

A. variable name = value;

B. var name = value;

C. let name = value;

D. all of the above

Discuss Work Space

Answer: option c

Explanation:

All of the options are syntactically valid, but the recommended way to declare a variable in modern JavaScript is using the let keyword.

27.

What is the output of the following code?

console.log(3 === "3");

A. 1

B. 0

C. NaN

D. null

Discuss Work Space

Answer: option b

Explanation:

The === operator in JavaScript tests for strict equality. The string "3" is not strictly equal to the number 3, so the expression evaluates to false.

28.

What is the output of the following code?

console.log("2" * "3");

A. 5

B. 6

C. 23

D. 6

Discuss Work Space

Answer: option b

Explanation:

The * operator in JavaScript performs multiplication. When used with strings, JavaScript tries to convert them to numbers before performing the operation.

29. Which of the following is a valid way to create a function in JavaScript?

A. function myFunction() {}

B. var myFunction = function() {};

C. const myFunction = () => {};

D. all of the above

Discuss Work Space

Answer: option d

Explanation:

All of the options are valid ways to create a function in JavaScript.

30.

What is the output of the following code?

console.log("hello".toUpperCase());

A. HELLO

B. hello

C. undefined

D. null

Discuss Work Space

Answer: option a

Explanation:

The toUpperCase() method in JavaScript converts a string to all uppercase letters.


Subscribe for Latest Career Trends
Subscribe Now
Use AI and ChatGPT for Career Guidance

Unlock Your Future

Join Now
Worried for Placements in 2024?

Join FAST TRACK Course

Join Now
Supercharge Your SUCCESS

Join All in One Placement Mock Tests-2024

Join Now