0% found this document useful (0 votes)
4 views12 pages

JavaScript Basics

The document contains a series of multiple-choice questions (MCQs) focused on JavaScript basics, covering topics such as comments, naming conventions, variables, data types, arithmetic operations, type coercion, comparison operators, type conversion functions, control flow, loops, and user interaction. Each question presents a scenario or concept with four possible answers, testing the reader's knowledge of JavaScript. The document does not provide answers to the questions.

Uploaded by

rmdanyoussef01
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views12 pages

JavaScript Basics

The document contains a series of multiple-choice questions (MCQs) focused on JavaScript basics, covering topics such as comments, naming conventions, variables, data types, arithmetic operations, type coercion, comparison operators, type conversion functions, control flow, loops, and user interaction. Each question presents a scenario or concept with four possible answers, testing the reader's knowledge of JavaScript. The document does not provide answers to the questions.

Uploaded by

rmdanyoussef01
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

JavaScript Basics – MCQ Questions (No Answers)

🔹 Comments & Naming Conventions


1. What naming convention is used in the following variable name?

firstName

A) snake_case
B) PascalCase
C) camelCase
D) kebab-case
2. Which of the following is a valid camelCase variable name?
A) first_name
B) FirstName
C) firstName
D) first-name
3. Which syntax is used for a single-line comment in JavaScript?
A)
B) /** */
C) //
D) ##
4. Which syntax correctly represents a multi-line comment?
A) // comment //
B)
C) / comment /
D) ## comment ##

🔹 Variables & Data Types


5. Which keyword is used to declare a variable in JavaScript?
A) int
B) string
C) var
D) boolean
6. What is the data type of the following value?

var x = 9;

A) int
B) float
C) number
D) double
7. What is the data type of this value?

var number = 9.8;

A) float
B) number
C) decimal
D) double
8. What is the data type of the following?

var flag = true;

A) string
B) boolean
C) number
D) undefined
9. What will be the value of x ?

var x;

A) null
B) 0
C) undefined
D) NaN
10. What will be printed?

[Link](typeof x);

(Assume x is declared but not initialized)

A) object
B) number
C) undefined
D) null
🔹 Arithmetic & Concatenation
11. What is the result of the following?

var name = "ahmed";


[Link](name + 20);

A) ahmed
B) ahmed20
C) Error
D) NaN

12. What will be printed?

[Link](20 + 30 + "10");

A) 201010
B) 5010
C) 60
D) Error

13. What will be printed?

[Link]("501020");

A) 501020
B) 102050
C) Error
D) NaN

14. What is the output?

[Link]("ahmed" + " omar");

A) ahmedomar
B) ahmed omar
C) Error
D) NaN

15. What is the output?


[Link](12 + "true" + "sara");

A) 12truesara
B) 13sara
C) Error
D) NaN

🔹 Type Coercion
16. In JavaScript, true is converted to which number during arithmetic operations?

A) 0
B) 1
C) -1
D) NaN

17. What will be printed?

[Link](12 + null);

A) 12
B) null
C) NaN
D) Error

18. What will be printed?

[Link](20 - 12);

A) 8
B) 32
C) Error
D) NaN

19. What is the output?

[Link]("sara" + {});

A) sara
B) sara[object Object]
C) Error
D) NaN

🔹 Comparison Operators
20. What does the == operator compare?

A) Value only
B) Type only
C) Value and type
D) Reference

21. What does the === operator compare?

A) Value only
B) Type only
C) Value and type
D) Memory address

22. What is the result?

[Link](8 == "8");

A) true
B) false
C) Error
D) NaN

23. What is the result?

[Link](1 == true);

A) true
B) false
C) Error
D) undefined

24. What will be printed?


[Link](true == "true");

A) true
B) false
C) Error
D) NaN

25. What is the result?

[Link](null == 0);

A) true
B) false
C) Error
D) NaN

26. What will be printed?

[Link](undefined == undefined);

A) true
B) false
C) Error
D) NaN

27. What is the result?

[Link]({} == null);

A) true
B) false
C) Error
D) NaN

🔹 Type Conversion Functions


28. What is the value of the following?

var x = Number(null);
A) null
B) 0
C) NaN
D) undefined

29. What is the type of the following value?

var y = String(true);

A) boolean
B) number
C) string
D) undefined

30. What will be the value of the following?

var z = Boolean(89);

A) false
B) true
C) NaN
D) undefined

🔹 Special Cases & NaN


31. What will be printed?

[Link]([] == []);

A) true
B) false
C) Error
D) NaN

32. What is the output?

[Link](null + null);

A) null
B) 0
C) NaN
D) Error

33. What is the result?

[Link](null + 0);

A) 0
B) null
C) NaN
D) Error

34. What will be printed?

[Link](20 + null);

A) 20
B) null
C) NaN
D) Error

35. What is the output?

[Link](undefined + undefined);

A) 0
B) undefined
C) NaN
D) Error

36. What will be printed?

[Link]("sara" - 40);

A) sara40
B) 40
C) NaN
D) Error

37. What is the result?

[Link]("50" - 40);
A) "10"
B) 10
C) NaN
D) Error

38. What will be printed?

[Link](1 - NaN);

A) 1
B) NaN
C) 0
D) Error

39. What is the output?

[Link](40 - true);

A) 39
B) 40
C) NaN
D) Error

40. What is the result?

[Link](NaN === NaN);

A) true
B) false
C) Error
D) undefined

41. What does the following return?

[Link]("sara" - 7);

A) true
B) false
C) NaN
D) Error
🔹 Control Flow (If – Ternary)
42. Which statement is used to execute code based on a condition?

A) for
B) if
C) switch
D) function

43. What will be printed if time = 12 ?

if(time < 9){


[Link]("Good Morning");
} else if(time < 14){
[Link]("Good Day");
} else {
[Link]("Good Evening");
}

A) Good Morning
B) Good Day
C) Good Evening
D) Nothing

44. What is the correct syntax of the ternary operator?

A) condition : true ? false


B) if ? else
C) condition ? true : false
D) true : false ? condition

45. What will be printed?

var color = "rehhhd";


color == "red" ? [Link]("red") : [Link]("another color");

A) red
B) another color
C) Error
D) NaN
🔹 Switch Statement
46. What happens if break is missing in a switch case?

A) Error occurs
B) Switch stops automatically
C) Execution continues to the next case
D) Default executes only

🔹 Loops
47. How many times will this loop execute?

for(var i = 0; i <= 3; i++){


[Link](i);
}

A) 3
B) 4
C) 5
D) Infinite

48. What does the following loop represent?

for( ; ; ){
[Link]("infinite loop");
break;
}

A) Syntax error
B) Infinite loop without exit
C) Infinite loop with manual stop
D) Conditional loop

49. What does continue do inside a loop?

A) Stops the loop completely


B) Skips the current iteration
C) Restarts the loop
D) Ends the program
50. What does break do inside a loop?

A) Skips one iteration


B) Stops the loop completely
C) Pauses execution
D) Restarts the loop

🔹 User Interaction
51. What does prompt() return if the user clicks Cancel?

A) ""
B) 0
C) null
D) undefined

52. What is the return type of confirm() ?

A) string
B) number
C) boolean
D) undefined

53. What will be logged?

var x = confirm("Are you sure?");


[Link](x);

A) "yes" or "no"
B) true or false
C) 1 or 0
D) OK or Cancel

You might also like