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 JavaScript data type?
-
String
-
Number
-
Boolean
-
All of the above
D
Correct answer
Explanation
JavaScript has three primitive data types: String, Number, and Boolean. It also has a special data type called null and a global object called undefined.
What is the significance of dependent types?
-
They enable more expressive type systems
-
They improve program verification techniques
-
They enhance the security of programming languages
-
They facilitate the development of type-safe libraries
A
Correct answer
Explanation
Dependent types allow for more precise and expressive type systems, enabling the representation of complex relationships between data.
What is the role of type inference in Type Theory?
-
To automatically determine the type of an expression
-
To verify the correctness of a program
-
To optimize the execution of a program
-
To generate test cases for a program
A
Correct answer
Explanation
Type inference in Type Theory is the process of automatically deducing the type of an expression based on its structure and the types of its components.
What is the correct syntax for declaring a variable in JavaScript?
-
var variableName;
-
let variableName;
-
const variableName;
-
All of the above
D
Correct answer
Explanation
In JavaScript, you can declare a variable using the var, let, or const keyword, followed by the variable name and a semicolon.
What is the difference between var, let, and const in JavaScript?
-
var is used for global variables, let is used for local variables, and const is used for constants.
-
var is used for variables that can be reassigned, let is used for variables that cannot be reassigned, and const is used for constants.
-
var is used for variables that are declared at the top of a function, let is used for variables that are declared within a block, and const is used for constants.
-
None of the above
Correct answer
Explanation
In JavaScript, let is used for variables that cannot be reassigned, and const is used for constants. var is used for variables that can be reassigned, but it is generally discouraged to use var in modern JavaScript code.
What is the correct syntax for creating a function in JavaScript?
-
function functionName() { ... }
-
const functionName = () => { ... }
-
let functionName = () => { ... }
-
All of the above
D
Correct answer
Explanation
In JavaScript, you can create a function using the function keyword, followed by the function name and parentheses. You can also create a function using an arrow function, which is a concise syntax for writing a function. Arrow functions can be written using the const or let keyword, followed by the arrow (=>) symbol and the function body.
What is the difference between a function declaration and a function expression in JavaScript?
-
A function declaration is hoisted to the top of the scope, while a function expression is not.
-
A function declaration can be called before it is defined, while a function expression cannot.
-
A function declaration can be used as a value, while a function expression cannot.
-
None of the above
A
Correct answer
Explanation
In JavaScript, a function declaration is hoisted to the top of the scope, which means that it can be called before it is defined. A function expression is not hoisted, so it cannot be called before it is defined.
What is the correct syntax for creating an array in JavaScript?
-
const arrayName = [];
-
let arrayName = [];
-
var arrayName = [];
-
All of the above
D
Correct answer
Explanation
In JavaScript, you can create an array using the const, let, or var keyword, followed by the array name and square brackets.
What is the correct syntax for creating an object in JavaScript?
-
const objectName = {};
-
let objectName = {};
-
var objectName = {};
-
All of the above
D
Correct answer
Explanation
In JavaScript, you can create an object using the const, let, or var keyword, followed by the object name and curly braces.
What is the correct syntax for creating a loop in JavaScript?
-
for (let i = 0; i < array.length; i++) { ... }
-
for (const i in array) { ... }
-
for (const i of array) { ... }
-
All of the above
D
Correct answer
Explanation
In JavaScript, there are three types of loops: the for loop, the for...in loop, and the for...of loop. The for loop is used to iterate over a range of numbers, the for...in loop is used to iterate over the properties of an object, and the for...of loop is used to iterate over the elements of an array.
What is the difference between a break statement and a continue statement in JavaScript?
-
A break statement exits the loop immediately, while a continue statement skips the current iteration of the loop and continues with the next iteration.
-
A break statement exits the loop immediately, while a continue statement exits the current iteration of the loop and starts the next iteration.
-
A break statement skips the current iteration of the loop and continues with the next iteration, while a continue statement exits the loop immediately.
-
None of the above
A
Correct answer
Explanation
In JavaScript, a break statement exits the loop immediately, while a continue statement skips the current iteration of the loop and continues with the next iteration.
What is the correct syntax for creating a conditional statement in JavaScript?
-
if (condition) { ... }
-
if (condition) { ... } else { ... }
-
if (condition) { ... } else if (condition) { ... } else { ... }
-
All of the above
D
Correct answer
Explanation
In JavaScript, there are three types of conditional statements: the if statement, the if...else statement, and the if...else if...else statement. The if statement is used to execute a block of code if a condition is true, the if...else statement is used to execute one block of code if a condition is true and another block of code if the condition is false, and the if...else if...else statement is used to execute one block of code if a condition is true, another block of code if a different condition is true, and a third block of code if both conditions are false.
What is the correct syntax for creating a function in JavaScript?
-
function functionName() { ... }
-
const functionName = () => { ... }
-
let functionName = () => { ... }
-
All of the above
D
Correct answer
Explanation
In JavaScript, you can create a function using the function keyword, followed by the function name and parentheses. You can also create a function using an arrow function, which is a concise syntax for writing a function. Arrow functions can be written using the const or let keyword, followed by the arrow (=>) symbol and the function body.
How do you define a function in JavaScript?
-
function functionName() {}
-
functionName() {}
-
var functionName = function() {}
-
var functionName = {}
A
Correct answer
Explanation
To define a function in JavaScript, you use the function keyword followed by the function name and parentheses. Inside the parentheses, you specify the parameters that the function will receive. The function body, where the code that will be executed when the function is called is placed, is enclosed in curly braces.
How do you call a function in JavaScript?
-
functionName();
-
functionName
-
functionName = ();
-
functionName {}
A
Correct answer
Explanation
To call a function in JavaScript, you simply use the function name followed by parentheses. You can pass arguments to the function by placing them inside the parentheses when you call the function.