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

What is the difference between a function declaration and a function expression?

  1. Function declarations are hoisted, while function expressions are not.

  2. Function expressions can be used as values, while function declarations cannot.

  3. Function declarations can be named, while function expressions cannot.

  4. All of the above

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

Function declarations are hoisted to the top of their scope, while function expressions are not. Function expressions can be used as values, while function declarations cannot. Function declarations can be named, while function expressions cannot.

Multiple choice

What is a callback function?

  1. A function that is passed as an argument to another function

  2. A function that is called from within another function

  3. A function that is defined inside another function

  4. All of the above

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

A callback function is a function that is passed as an argument to another function. The callback function is then called from within the other function. Callback functions are often used to handle asynchronous operations.

Multiple choice

What is a closure in JavaScript?

  1. A function that has access to the variables of its outer scope, even after the outer scope has finished executing.

  2. A function that is defined inside another function.

  3. A function that can be called multiple times.

  4. None of the above

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

A closure in JavaScript is a function that has access to the variables of its outer scope, even after the outer scope has finished executing. This is because the function retains a reference to the outer scope's variables.

Multiple choice

Which of the following is a conditional statement in JavaScript?

  1. if

  2. for

  3. while

  4. do-while

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

The 'if' statement is a conditional statement in JavaScript. It allows you to execute a block of code only if a certain condition is met.

Multiple choice

What is the syntax of an 'if' statement in JavaScript?

  1. if (condition) { statement }

  2. if condition { statement }

  3. if (condition) statement

  4. if condition statement

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

The syntax of an 'if' statement in JavaScript is 'if (condition) { statement }', where 'condition' is the condition that determines whether the statement will be executed or not.

Multiple choice

Which of the following is a loop statement in JavaScript?

  1. if

  2. for

  3. while

  4. do-while

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

The 'for' statement is a loop statement in JavaScript. It allows you to execute a block of code multiple times, based on a specified condition.

Multiple choice

What is the syntax of a 'for' loop in JavaScript?

  1. for (initialization; condition; increment) { statement }

  2. for initialization; condition; increment { statement }

  3. for (initialization; condition) statement

  4. for initialization condition increment statement

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

The syntax of a 'for' loop in JavaScript is 'for (initialization; condition; increment) { statement }', where 'initialization' is the initial value of the loop variable, 'condition' is the condition that determines whether the loop will continue to execute, and 'increment' is the value by which the loop variable is incremented after each iteration.

Multiple choice

Which of the following is a type of loop that executes a block of code at least once, and then continues to execute the block as long as a certain condition is met?

  1. for

  2. while

  3. do-while

  4. switch

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

The 'do-while' loop is a type of loop that executes a block of code at least once, and then continues to execute the block as long as a certain condition is met.

Multiple choice

What is the syntax of a 'do-while' loop in JavaScript?

  1. do { statement } while (condition);

  2. do statement while (condition);

  3. do { statement } while condition;

  4. do statement while condition;

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

The syntax of a 'do-while' loop in JavaScript is 'do { statement } while (condition);', where 'statement' is the block of code to be executed, and 'condition' is the condition that determines whether the loop will continue to execute.

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.