menu

JavaScript Basic Programs for Beginners

JavaScript Basic Programs for Beginners - Important Points


1.

What is the correct syntax for declaring a JavaScript variable?

A. var x;

B. x = var;

C. variable x;

D. x = variable;

Discuss Work Space

Answer: option a

Explanation:

The correct syntax for declaring a JavaScript variable is "var variableName;"


2.

What is the output of the following program?

 console.log(3 + 4 + "5");

A. 12

B. 75

C. 345

D. 7+5

Discuss Work Space

Answer: option b

Explanation:

The output of the code is "75" because the first two numbers are added (3 + 4 = 7) and then the result is concatenated with the string "5".

3. Which of the following is NOT a valid way to comment in JavaScript?

A. // This is a comment

B. /* This is a comment /

C.

D. # This is a comment

Discuss Work Space

Answer: option d

Explanation:

The correct way to comment in JavaScript is by using "//" for single-line comments or "/ */" for multi-line comments.

4.

What is the output of the following program?

console.log(typeof "hello");

A. number

B. string

C. boolean

D. undefined

Discuss Work Space

Answer: option b

Explanation:

The output of the code is "string" because "hello" is a string.

5. Which of the following is the correct way to create a function in JavaScript?

A. function myFunction() {}

B. var myFunction = function() {};

C. myFunction = function() {};

D. All of the above are correct.

Discuss Work Space

Answer: option d

Explanation:

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


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