Javascript Fundamentals Flashcards
What is a variable?
A variable is a container that holds a value, which can be of various data types, such as numbers, strings, booleans, or objects.
What are the primitive data types in JavaScript?
The primitive data types in JavaScript are number, string, boolean, undefined, and null.
What is the difference between let and var in JavaScript?
The main difference between let and var is their scope. Variables declared with var have function scope, while variables declared with let have block scope. Additionally, variables declared with let cannot be redeclared in the same scope.
What is a constant in JavaScript?
A constant is a variable that cannot be reassigned a new value once it has been initialized. In JavaScript, constants are declared using the const keyword.
What is type coercion in JavaScript?
Type coercion is the automatic conversion of one data type to another data type. In JavaScript, this can happen implicitly (automatically) or explicitly (manually). For example, concatenating a string with a number will result in the number being implicitly converted to a string.
What is the difference between a string and a number in JavaScript?
A string is a sequence of characters enclosed in quotes, while a number is a numerical value. In JavaScript, you can perform arithmetic operations on numbers, but not on strings.
What is a boolean in JavaScript?
A boolean is a data type that represents one of two possible values: true or false.
What is a NaN in JavaScript?
NaN stands for “Not a Number”. It is a special value in JavaScript that represents an undefined or unrepresentable value resulting from an arithmetic operation.
What is a null value in JavaScript?
Null is a special value in JavaScript that represents the intentional absence of any object value. It is often used to represent a non-existent or empty object.
What is the difference between undefined and null in JavaScript?
Undefined represents a variable that has been declared but has not been assigned a value, while null represents an intentional absence of any object value.
What is a conditional statement in JavaScript?
A conditional statement is a control flow structure that allows the program to make decisions based on certain conditions. In JavaScript, conditional statements are implemented using if/else and switch statements.
What is the difference between if and switch statements in JavaScript?
If statements allow for the evaluation of a single condition, whereas switch statements can evaluate multiple conditions based on different cases. If statements are more flexible and can handle more complex conditions, while switch statements are useful when there are multiple conditions that need to be evaluated.
What is a loop in JavaScript?
A loop is a control flow structure that allows the program to repeat a block of code multiple times. In JavaScript, the two most common types of loops are the for loop and the while loop.
What is the difference between a for loop and a while loop in JavaScript?
A for loop is typically used when you know the number of times you want to loop in advance, while a while loop is used when you want to loop until a certain condition is met. Both loops can be used interchangeably in many cases, but the choice of loop structure depends on the specific use case.
What is a break statement in JavaScript?
A break statement is a control flow statement that allows the program to exit a loop early. It can be used to terminate a loop when a certain condition is met.
What is a conditional (ternary) operator in JavaScript?
A conditional operator is a shorthand way of writing an if/else statement in a single line of code. It uses the ? and : symbols to evaluate a condition and return one of two values based on the condition.
What is a switch statement in JavaScript?
A switch statement is a control flow structure that allows the program to evaluate multiple conditions based on different cases. It is often used as a more readable alternative to a series of if/else statements.
What is a for…in loop in JavaScript?
A for…in loop is a control flow structure that allows the program to loop through the properties of an object. It is commonly used to iterate over the properties of an object and perform a certain action for each property.
What is a for…of loop in JavaScript?
A for…of loop is a control flow structure that allows the program to loop through the values of an iterable object, such as an array or a string. It is commonly used to iterate over the values of an iterable and perform a certain action for each value.
What is a continue statement in JavaScript?
A continue statement is a control flow statement that allows the program to skip a certain iteration of a loop and continue to the next iteration. It is commonly used to skip over certain values or conditions within a loop.
What is a function in JavaScript?
A function in JavaScript is a block of code that performs a specific task and can be called or invoked multiple times throughout the program. It can accept inputs or arguments, and can return a value as output.
What is a function declaration in JavaScript?
A function declaration in JavaScript is a way to create a named function that can be called or invoked at any point in the program. It has a function name, optional parameters, and a block of code that defines the function’s behavior.
What is a function expression in JavaScript?
A function expression in JavaScript is a way to define a function as a variable or constant, and assign the function to that variable. It can be called or invoked like any other variable, and can be anonymous or named.
What is a higher-order function in JavaScript?
A higher-order function in JavaScript is a function that takes one or more functions as arguments, or returns a function as its output. It is commonly used for code reuse, abstraction, and building more complex programs.
What is a callback function in JavaScript?
A callback function in JavaScript is a function that is passed as an argument to another function, and is executed within that function at a specific point in the code. It is commonly used for event handling, asynchronous programming, and building more modular programs.
What is a function parameter in JavaScript?
A function parameter in JavaScript is a variable that is passed into a function as an input or argument. It is defined in the function declaration or expression, and can be used within the function to perform a specific task.
What is a function return value in JavaScript?
A function return value in JavaScript is the value that is returned by a function after it has completed its execution. It can be any data type, and is specified using the return keyword in the function declaration or expression.
What is a named function in JavaScript?
A named function in JavaScript is a function that has a specific name defined in the function declaration or expression. It can be called or invoked using its name throughout the program.
What is an anonymous function in JavaScript?
An anonymous function in JavaScript is a function that does not have a specific name defined in the function declaration or expression. It can be assigned to a variable or passed as an argument to another function.
What is a recursive function in JavaScript?
A recursive function in JavaScript is a function that calls itself within its own code block. It is commonly used for solving problems that can be broken down into smaller sub-problems, such as searching a tree structure or calculating a factorial.
What is a function expression with arrow syntax in JavaScript?
A function expression with arrow syntax in JavaScript is a concise way to define a function that uses the arrow operator (=>) instead of the function keyword. It can be used as an anonymous or named function, and can have one or more parameters.
What is a rest parameter in a JavaScript function?
A rest parameter in a JavaScript function is denoted by three dots (…) before a parameter name, and allows a function to accept an indefinite number of arguments as an array. It is commonly used for functions that need to handle a variable number of arguments, such as array methods or event handlers.
What is a default parameter in a JavaScript function?
A default parameter in a JavaScript function is a value assigned to a parameter in the function declaration or expression, which is used if no argument is passed to the function for that parameter. It is commonly used for functions that have optional parameters or need to handle missing data.
What is a pure function in JavaScript?
A pure function in JavaScript is a function that has no side effects and always returns the same output for a given input. It does not modify any external state or data, and is commonly used for functions that need to be predictable, testable, and reusable.