Computer Knowledge
Programming Fundamentals
2,381 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 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.
What is the data type of a variable that can store true or false?
-
Number
-
String
-
Boolean
-
Undefined
C
Correct answer
Explanation
In JavaScript, the Boolean data type is used to store true or false values.
What is the purpose of the Array.prototype.sort() method in JavaScript?
-
To sort the elements of an array in ascending order
-
To sort the elements of an array in descending order
-
To sort the elements of an array in a custom order
-
To reverse the order of the elements in an array
C
Correct answer
Explanation
The Array.prototype.sort() method sorts the elements of an array in a custom order. The order is determined by a compare function that is passed to the method.