Javascript Fundamentals Flashcards

1
Q

What is a variable?

A

A variable is a container that holds a value, which can be of various data types, such as numbers, strings, booleans, or objects.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the primitive data types in JavaScript?

A

The primitive data types in JavaScript are number, string, boolean, undefined, and null.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the difference between let and var in JavaScript?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a constant in JavaScript?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is type coercion in JavaScript?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the difference between a string and a number in JavaScript?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a boolean in JavaScript?

A

A boolean is a data type that represents one of two possible values: true or false.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a NaN in JavaScript?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a null value in JavaScript?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the difference between undefined and null in JavaScript?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a conditional statement in JavaScript?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the difference between if and switch statements in JavaScript?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a loop in JavaScript?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the difference between a for loop and a while loop in JavaScript?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is a break statement in JavaScript?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is a conditional (ternary) operator in JavaScript?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is a switch statement in JavaScript?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is a for…in loop in JavaScript?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is a for…of loop in JavaScript?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is a continue statement in JavaScript?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is a function in JavaScript?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What is a function declaration in JavaScript?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What is a function expression in JavaScript?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What is a higher-order function in JavaScript?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

What is a callback function in JavaScript?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

What is a function parameter in JavaScript?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

What is a function return value in JavaScript?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

What is a named function in JavaScript?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

What is an anonymous function in JavaScript?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

What is a recursive function in JavaScript?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

What is a function expression with arrow syntax in JavaScript?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

What is a rest parameter in a JavaScript function?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

What is a default parameter in a JavaScript function?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

What is a pure function in JavaScript?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

What is a closure in JavaScript?

A

A closure in JavaScript is a combination of a function and the lexical environment in which it was defined. It allows a function to access and manipulate variables in its outer scope, even after that scope has been exited. Closures are commonly used for creating private variables, event handlers, and asynchronous programming.

36
Q

What is an array in JavaScript?

A

An array in JavaScript is a data structure that stores a collection of values, which can be of any data type, and can be accessed and manipulated by their index position.

37
Q

What is the length property of an array in JavaScript?

A

The length property of an array in JavaScript is a built-in property that returns the number of elements in an array.

38
Q

What is the push method of an array in JavaScript?

A

The push method of an array in JavaScript is a built-in method that adds one or more elements to the end of an array, and returns the new length of the array.

39
Q

What is the pop method of an array in JavaScript?

A

The pop method of an array in JavaScript is a built-in method that removes the last element of an array, and returns that element.

40
Q

What is the splice method of an array in JavaScript?

A

The splice method of an array in JavaScript is a built-in method that adds or removes elements from an array, and returns the removed elements. It can be used to insert, replace, or delete elements from an array at a specified index position.

41
Q

What is an object in JavaScript?

A

An object in JavaScript is a data structure that stores a collection of key-value pairs, where the keys are strings and the values can be of any data type.

42
Q

What is the dot notation for accessing object properties in JavaScript?

A

The dot notation for accessing object properties in JavaScript is a syntax that uses a dot (.) to separate the object name from the property name, such as object.property.

43
Q

What is the bracket notation for accessing object properties in JavaScript?

A

The bracket notation for accessing object properties in JavaScript is a syntax that uses square brackets ([ ]) to enclose the property name, and can also use a variable or expression to dynamically access the property, such as object[“property”] or object[variable].

44
Q

What is the difference between splice() and slice() in JavaScript?

A

splice() is a method that can be used to add, remove, or replace elements in an array at a specific index, while slice() is a method that can be used to extract a section of an array and return it as a new array.

45
Q

What is the forEach() method in JavaScript?

A

The forEach() method in JavaScript is a method that can be used to iterate over the elements of an array and perform a function on each element.

46
Q

What is the find() method in JavaScript?

A

The find() method in JavaScript is a method that can be used to find the first element in an array that satisfies a given condition, as specified by a callback function.

47
Q

What is the findIndex() method in JavaScript?

A

The findIndex() method in JavaScript is a method that can be used to find the index of the first element in an array that satisfies a given condition, as specified by a callback function.

48
Q

What is the filter() method in JavaScript?

A

The filter() method in JavaScript is a method that can be used to create a new array with all elements that pass a given condition, as specified by a callback function.

49
Q

What is the map() method in JavaScript?

A

The map() method in JavaScript is a method that can be used to create a new array with the results of calling a provided function on every element in the array.

50
Q

What is the reduce() method in JavaScript?

A

The reduce() method in JavaScript is a method that can be used to reduce an array to a single value, by applying a provided function on each element in the array. The function takes two arguments: an accumulator and the current element.

51
Q

What is the sort() method in JavaScript?

A

The sort() method in JavaScript is a method that can be used to sort the elements of an array in place. By default, the method sorts the elements in ascending order, but you can also specify a custom sorting function to sort the elements in a specific way. Note that the sort() method modifies the original array and does not create a new one.

52
Q

What is scope in JavaScript?

A

Scope in JavaScript refers to the visibility and accessibility of variables, functions, and objects in different parts of a program. Variables and functions can have different levels of visibility depending on where they are declared and where they are accessed.

53
Q

What is the difference between global and local scope in JavaScript?

A

Global scope refers to variables or functions that are accessible throughout the entire program, while local scope refers to variables or functions that are only accessible within a particular function or block of code.

54
Q

What is a closure in JavaScript?

A

A closure in JavaScript is a feature that allows a function to access variables and functions from its outer (enclosing) scope, even after the outer function has returned. Closures can be used to create private variables and functions, and to pass state between functions.

55
Q

What is the difference between a reference error and a type error in JavaScript?

A

A reference error in JavaScript occurs when you try to reference a variable or function that does not exist. A type error occurs when you try to use a value in a way that is not allowed by its data type (e.g., treating a string as a number).

56
Q

What is variable hoisting in JavaScript?

A

Variable hoisting in JavaScript is a feature that allows you to use a variable before it has been declared. When a variable is hoisted, it is moved to the top of its scope, so that it can be used throughout the scope.

57
Q

What is the difference between var, let, and const in JavaScript?

A

var, let, and const are all used to declare variables in JavaScript, but they have different scoping rules and behaviors. var has function scope and can be redeclared and reassigned, while let and const have block scope and cannot be redeclared but can be reassigned. const variables are also read-only and cannot be reassigned.

58
Q

What is lexical scoping in JavaScript?

A

Lexical scoping in JavaScript is a feature that determines variable scope based on the physical location of the variable in the source code. This means that variables declared in an outer function are visible to inner functions, but variables declared in an inner function are not visible to outer functions.

59
Q

What is a self-invoking function in JavaScript?

A

A self-invoking function in JavaScript is a function that is automatically executed as soon as it is defined. It is also known as an Immediately Invoked Function Expression (IIFE), and is often used to create private variables and functions.

60
Q

What is the this keyword in JavaScript?

A

The this keyword in JavaScript is a special variable that refers to the current object, or the object that the function is a method of. The value of this is determined at runtime based on how the function is called.

61
Q

What is the difference between a shallow copy and a deep copy in JavaScript?

A

A shallow copy in JavaScript creates a new object or array that references the same values as the original object or array. A deep copy creates a new object or array with new values, so that changes to the new object or array do not affect the original object or array.

62
Q

What is object-oriented programming in JavaScript?

A

Object-oriented programming (OOP) is a programming paradigm that focuses on creating objects and classes that can be reused and extended. In JavaScript, objects can be created using object literals, constructor functions, and classes.

63
Q

What is an object literal in JavaScript?

A

An object literal is a way of creating an object in JavaScript using curly braces {}. The properties of the object are defined within the braces, separated by commas.

64
Q

What is a constructor function in JavaScript?

A

A constructor function in JavaScript is a function that is used to create new objects with the same properties and methods. Constructor functions are used with the new keyword to create instances of the object.

65
Q

What is a class in JavaScript?

A

A class in JavaScript is a template for creating objects with the same properties and methods. Classes were introduced in ECMAScript 2015 and provide a more intuitive syntax for creating objects and working with inheritance.

66
Q

What is inheritance in JavaScript?

A

Inheritance in JavaScript is the process of creating new objects that are based on existing objects. Inheritance can be achieved using prototype chains, where objects inherit properties and methods from their parent objects.

67
Q

What is the difference between composition and inheritance in JavaScript?

A

Composition in JavaScript is the process of creating complex objects by combining simpler objects. Inheritance is the process of creating new objects that are based on existing objects. Composition is generally favored over inheritance in JavaScript because it is more flexible and less prone to bugs.

68
Q

What is polymorphism in JavaScript?

A

Polymorphism in JavaScript refers to the ability of objects to take on different forms or behave in different ways. Polymorphism can be achieved through method overriding and method overloading.

69
Q

What is encapsulation in JavaScript?

A

Encapsulation in JavaScript refers to the idea of hiding the implementation details of an object and exposing only the necessary methods and properties. This helps to prevent accidental modification of the object’s internal state and makes the object easier to use.

70
Q

What is a prototype in JavaScript?

A

A prototype in JavaScript is an object that is used as a template for creating other objects. Each object in JavaScript has a prototype, which can be used to add new properties and methods to the object.

71
Q

What is the super keyword in JavaScript?

A

The super keyword in JavaScript is used to call a method from a parent class or constructor. It is often used in conjunction with inheritance to access and modify properties and methods from parent objects.

72
Q

What is asynchronous programming in JavaScript?

A

Asynchronous programming in JavaScript allows multiple tasks to run in the background while the main program continues to run. This is useful for tasks that take a long time to complete, such as network requests and file I/O.

73
Q

What is a callback function in JavaScript?

A

A callback function in JavaScript is a function that is passed as an argument to another function and is executed after the first function has completed its task. Callbacks are often used in asynchronous programming to handle the results of an asynchronous operation.

74
Q

What is the Document Object Model (DOM) in JavaScript?

A

The Document Object Model (DOM) in JavaScript is a representation of the structure and content of a web page. It is a hierarchical tree-like structure of objects that can be manipulated using JavaScript to dynamically update the content and styling of the web page.

75
Q

What is the difference between the innerHTML and textContent properties in JavaScript?

A

The innerHTML property in JavaScript is used to get or set the HTML content of an element, including any child elements and their attributes. The textContent property, on the other hand, is used to get or set only the text content of an element, excluding any child elements and their attributes.

76
Q

What is the querySelector method in JavaScript?

A

The querySelector method in JavaScript is a method that allows you to select an element in the DOM by using a CSS selector. It returns the first element that matches the selector, or null if no element matches.

77
Q

What is the createElement method in JavaScript?

A

The createElement method in JavaScript is a method that allows you to create a new element in the DOM with the specified tag name. You can then set the attributes and content of the element and add it to the DOM using the appropriate methods.

78
Q

What is the appendChild method in JavaScript?

A

The appendChild method in JavaScript is a method that allows you to add a new child element to an existing element in the DOM. The new element is added as the last child of the parent element.

79
Q

What is the removeChild method in JavaScript?

A

The removeChild method in JavaScript is a method that allows you to remove a child element from an existing element in the DOM. The child element to be removed is specified as an argument to the method.

80
Q

What is the setAttribute method in JavaScript?

A

The setAttribute method in JavaScript is a method that allows you to set an attribute on an element in the DOM. The method takes two arguments: the name of the attribute and its value.

81
Q

What is the getAttribute method in JavaScript?

A

The getAttribute method in JavaScript is a method that allows you to get the value of an attribute on an element in the DOM. The method takes one argument: the name of the attribute.

82
Q

What is the classList property in JavaScript?

A

The classList property in JavaScript is a property of an element in the DOM that allows you to add, remove, or toggle CSS classes on the element. It provides methods such as add, remove, and toggle for manipulating the classes.

83
Q

What is the difference between the createElement method and the createTextNode method in JavaScript?

A

The createElement method in JavaScript is used to create a new element with the specified tag name, while the createTextNode method is used to create a new text node with the specified content. Text nodes are used to represent the text content of an element.

84
Q

What is event delegation in JavaScript?

A

Event delegation in JavaScript is a technique for handling events on multiple elements with a single event listener. Instead of attaching an event listener to each individual element, you attach a single event listener to a parent element and check which child element triggered the event using the event.target property.

85
Q

What is the querySelectorAll method in JavaScript?

A

The querySelectorAll method in JavaScript is a method that allows you to select multiple elements in the DOM by using a CSS selector. It returns a NodeList that contains all the elements that match the selector.

86
Q

What is the addEventListener method in JavaScript?

A

The addEventListener method in JavaScript is a method that allows you to attach an event listener to an element in the DOM. The method takes two arguments: the type of the event and the function to be executed when the event is triggered.

87
Q

What is the removeEventListener method in JavaScript?

A

The removeEventListener method in JavaScript is a method that allows you to remove an event listener from an element in the DOM. The method takes two arguments: the type of the event and the function to be removed.