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

Multiple choice

Which of the following is a statement that allows you to exit a function or a loop immediately, and return a value?

  1. break

  2. continue

  3. return

  4. throw

Reveal answer Fill a bubble to check yourself
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.

Multiple choice

What is the syntax of a 'return' statement in JavaScript?

  1. return value;

  2. return statement value;

  3. return condition value;

  4. return variable value;

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The syntax of a 'return' statement in JavaScript is 'return value;', where 'value' is the value being returned.

Multiple choice

Which of the following is a statement that allows you to throw an error in JavaScript?

  1. break

  2. continue

  3. return

  4. throw

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The 'throw' statement is a statement that allows you to throw an error in JavaScript.

Multiple choice

What is the syntax of a 'throw' statement in JavaScript?

  1. throw error;

  2. throw statement error;

  3. throw condition error;

  4. throw variable error;

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The syntax of a 'throw' statement in JavaScript is 'throw error;', where 'error' is the error being thrown.

Multiple choice

Which of the following is not a valid event phase in React?

  1. Capture

  2. Bubbling

  3. Target

  4. Passive

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

Passive is not a valid event phase in React. The valid event phases are Capture, Bubbling, and Target.

Multiple choice

In JavaScript, variables are declared using which keyword?

  1. var

  2. let

  3. const

  4. All of the above

Reveal answer Fill a bubble to check yourself
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.

Multiple choice

What is the data type of a variable that can store whole numbers?

  1. Number

  2. String

  3. Boolean

  4. Undefined

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

In JavaScript, the Number data type is used to store whole numbers.

Multiple choice

Which of the following is not a valid JavaScript data type?

  1. Number

  2. String

  3. Boolean

  4. Array

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

In JavaScript, Array is not a data type but a built-in object.

Multiple choice

What is the data type of a variable that can store text?

  1. Number

  2. String

  3. Boolean

  4. Undefined

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

In JavaScript, the String data type is used to store text.

Multiple choice

What is the data type of a variable that can store true or false?

  1. Number

  2. String

  3. Boolean

  4. Undefined

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

In JavaScript, the Boolean data type is used to store true or false values.

Multiple choice

What is the purpose of the Array.prototype.sort() method in JavaScript?

  1. To sort the elements of an array in ascending order

  2. To sort the elements of an array in descending order

  3. To sort the elements of an array in a custom order

  4. To reverse the order of the elements in an array

Reveal answer Fill a bubble to check yourself
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.