Computer Knowledge
Programming Fundamentals
2,611 Questions
Programming fundamentals form the core logic of software development and computer science. This includes variable declarations, pointer assignments, loop iterations, and exception handling. These technical topics are regularly tested in computer knowledge and IT officer competitive examinations.
Variables and arraysPointer assignmentsLoop iterationsException handling blocksCompile time errorsFunction references
Programming Fundamentals Questions
Which of the following is a statement that allows you to execute different blocks of code based on the value of a variable?
D
Correct answer
Explanation
The 'switch' statement is a statement that allows you to execute different blocks of code based on the value of a variable.
What is the syntax of a 'switch' statement in JavaScript?
-
switch (variable) { case value1: statement1; break; case value2: statement2; break; default: statement3; }
-
switch variable { case value1: statement1; break; case value2: statement2; break; default: statement3; }
-
switch (variable) case value1: statement1; break; case value2: statement2; break; default: statement3;
-
switch variable case value1: statement1; break; case value2: statement2; break; default: statement3;
A
Correct answer
Explanation
The syntax of a 'switch' statement in JavaScript is 'switch (variable) { case value1: statement1; break; case value2: statement2; break; default: statement3; }', where 'variable' is the variable whose value is being checked, 'value1' and 'value2' are the values being compared to the variable, 'statement1' and 'statement2' are the blocks of code to be executed if the variable matches 'value1' or 'value2', respectively, and 'statement3' is the block of code to be executed if the variable does not match any of the specified values.
Which of the following is a statement that allows you to terminate the execution of a loop or a switch statement?
-
break
-
continue
-
return
-
throw
A
Correct answer
Explanation
The 'break' statement is a statement that allows you to terminate the execution of a loop or a switch statement.
What is the syntax of a 'break' statement in JavaScript?
-
break;
-
break statement;
-
break condition;
-
break variable;
A
Correct answer
Explanation
The syntax of a 'break' statement in JavaScript is 'break;', where ';' is the statement terminator.
Which of the following is a statement that allows you to skip the current iteration of a loop and continue with the next iteration?
-
break
-
continue
-
return
-
throw
B
Correct answer
Explanation
The 'continue' statement is a statement that allows you to skip the current iteration of a loop and continue with the next iteration.
What is the syntax of a 'continue' statement in JavaScript?
-
continue;
-
continue statement;
-
continue condition;
-
continue variable;
A
Correct answer
Explanation
The syntax of a 'continue' statement in JavaScript is 'continue;', where ';' is the statement terminator.
Which of the following is a statement that allows you to exit a function or a loop immediately, and return a value?
-
break
-
continue
-
return
-
throw
C
Correct answer
Explanation
The 'return' statement is a statement that allows you to exit a function or a loop immediately, and return a value.
What is the syntax of a 'return' statement in JavaScript?
-
return value;
-
return statement value;
-
return condition value;
-
return variable value;
A
Correct answer
Explanation
The syntax of a 'return' statement in JavaScript is 'return value;', where 'value' is the value being returned.
Which of the following is a statement that allows you to throw an error in JavaScript?
-
break
-
continue
-
return
-
throw
D
Correct answer
Explanation
The 'throw' statement is a statement that allows you to throw an error in JavaScript.
What is the syntax of a 'throw' statement in JavaScript?
-
throw error;
-
throw statement error;
-
throw condition error;
-
throw variable error;
A
Correct answer
Explanation
The syntax of a 'throw' statement in JavaScript is 'throw error;', where 'error' is the error being thrown.
Which of the following is not a valid event phase in React?
-
Capture
-
Bubbling
-
Target
-
Passive
D
Correct answer
Explanation
Passive is not a valid event phase in React. The valid event phases are Capture, Bubbling, and Target.
In JavaScript, variables are declared using which keyword?
-
var
-
let
-
const
-
All of the above
D
Correct answer
Explanation
In JavaScript, variables can be declared using the keywords var, let, or const. var is used for variables that can be reassigned, let is used for variables that can be reassigned within a specific scope, and const is used for variables that cannot be reassigned.
What is the data type of a variable that can store whole numbers?
-
Number
-
String
-
Boolean
-
Undefined
A
Correct answer
Explanation
In JavaScript, the Number data type is used to store whole numbers.
Which of the following is not a valid JavaScript data type?
-
Number
-
String
-
Boolean
-
Array
D
Correct answer
Explanation
In JavaScript, Array is not a data type but a built-in object.
What is the data type of a variable that can store text?
-
Number
-
String
-
Boolean
-
Undefined
B
Correct answer
Explanation
In JavaScript, the String data type is used to store text.