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

Multiple choice

Which of the following is a statement that allows you to execute different blocks of code based on the value of a variable?

  1. if

  2. for

  3. while

  4. switch

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

Multiple choice

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

  1. switch (variable) { case value1: statement1; break; case value2: statement2; break; default: statement3; }

  2. switch variable { case value1: statement1; break; case value2: statement2; break; default: statement3; }

  3. switch (variable) case value1: statement1; break; case value2: statement2; break; default: statement3;

  4. switch variable case value1: statement1; break; case value2: statement2; break; default: statement3;

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

Multiple choice

Which of the following is a statement that allows you to terminate the execution of a loop or a switch statement?

  1. break

  2. continue

  3. return

  4. throw

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

The 'break' statement is a statement that allows you to terminate the execution of a loop or a switch statement.

Multiple choice

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

  1. break;

  2. break statement;

  3. break condition;

  4. break variable;

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

The syntax of a 'break' statement in JavaScript is 'break;', where ';' is the statement terminator.

Multiple choice

Which of the following is a statement that allows you to skip the current iteration of a loop and continue with the next iteration?

  1. break

  2. continue

  3. return

  4. throw

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

Multiple choice

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

  1. continue;

  2. continue statement;

  3. continue condition;

  4. continue variable;

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

The syntax of a 'continue' statement in JavaScript is 'continue;', where ';' is the statement terminator.

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.