1/438
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What is npm?
npm is a registry for JavaScript packages that allows developers to share and use packages, and provides private development management for organizations.
What is the purpose of the package.json file?
The package.json file keeps track of all the packages that a project relies on, as well as other metadata.
How can you generate a package.json file with default settings?
Use the command npm init -y to create a package.json file with default settings.
What command is used to install a package in a project?
Run npm install
How do you install a package as a developer dependency?
Use the command npm install
What does the command npm install do?
It installs all the packages listed in the package.json file.
Why should the node_modules directory not be tracked by git?
Because the list of dependencies can be large, it's better to have developers use npm install to install dependencies from package.json.
How do you tell git to ignore a file or directory?
Create a .gitignore file and list the files or directories to ignore.
What happens if a specific version of a package is not provided in package.json?
Running npm update can update the dependencies to the latest available version.
How do you remove a package from a project?
Run npm uninstall
What is the package-lock.json file?
It is automatically generated when npm install is used and typically does not need to be edited.
What is the purpose of the 'scripts' property in package.json?
It lists aliases for bash commands, allowing registered scripts to be run with npm.
How do you run a registered script with npm?
Execute npm run
What is the difference between global and local package installation in npm?
Global packages are available in any working directory, while local packages are only available in a specific working directory.
Why is it recommended to install packages locally?
Local installations prevent compatibility issues between different projects that may require different package versions.
What flag is used to install a package globally?
Use the -g flag to install a package globally.
What is Test-Driven Development (TDD)?
TDD is a workflow where tests are written before the code they validate, encouraging small, focused development steps.
What are some advantages of Test-Driven Development?
Advantages include improved code quality, fewer bugs, refactoring confidence, better understanding of requirements, and living documentation.
What does TDD encourage in terms of code design?
It encourages clearer, more modular design by writing tests first.
How does TDD help with bug detection?
It catches problems early, before the code is fully integrated.
What role does the test suite play in TDD?
The test suite provides a reliable description of what the code is meant to do, serving as living documentation.
At what levels can testing occur?
Testing can happen at different levels depending on what is being checked.
What is Unit Testing?
Testing a small unit of code (typically a function) for specific inputs/outputs.
What is Integration Testing?
Testing how different parts of the system work together, such as functions calling other functions or the frontend connecting to the backend.
What is End-to-End Testing?
Testing the application flow as a complete system, typically used to test vital functionality such as user login or payments.
What is the Red-Green-Refactor Cycle in TDD?
A process that involves identifying a behavior, writing a test, running the test (red), making it pass (green), refactoring, and repeating the cycle.
How do you identify a behavior in TDD?
By describing what the code is expected to do from an external point of view, including writing it in plain English.
What are the characteristics of a good test in TDD?
A good test is focused, readable, repeatable, and independent.
What does the 'Red' phase in TDD signify?
Running the test to check that it fails, proving that the test is valid and that the code doesn't already pass it.
What does the 'Green' phase in TDD involve?
Writing the simplest possible code to make the test pass.
What is the purpose of the Refactor phase in TDD?
To clean up the code for clarity and remove duplication without changing the behavior.
What is Test Coverage?
It refers to how thoroughly tests check the possible behaviors of a function, including expected, unusual, and invalid inputs.
What is the Happy Path in testing?
The expected, standard use case with typical input that should work without issues.
What are Edge Cases in testing?
Valid but unusual inputs that sit at the limits of what the function is expected to handle.
What does Sad Path refer to in testing?
Invalid inputs or scenarios that the function isn't designed to handle, checking whether errors are thrown or handled gracefully.
What is a robust test?
A test that checks what matters without breaking unnecessarily when code changes.
What is an example of a brittle test?
A test that fails due to small or irrelevant changes, such as checking the exact structure of an object.
What is a robust alternative to a brittle test?
A test that focuses on important behavior, such as checking if an object has a specific property with a certain value.
What is Jest?
A JavaScript Testing Framework with a focus on simplicity.
How should testing frameworks be installed?
As dev dependencies using the -D flag.
What is the first step in the Red-Green-Refactor cycle?
Identify a behavior that describes what the code is expected to do.
What should you consider when choosing an example input for a behavior?
Think about typical values as well as unusual ones.
What should you do after a test passes in TDD?
Refactor the code to improve clarity and remove duplication.
What is the importance of re-running tests after refactoring?
To ensure that the tests still pass and the behavior of the code hasn't changed.
What is the typical order of behaviors to test in TDD?
Start with happy path behaviors, then build up to edge cases and error handling.
What command is used to install Jest as a development dependency?
npm i -D jest
How can tests be executed using a script in package.json?
By adding a script entry: "scripts": { "test": "jest" }
What file extensions does Jest look for by default?
.js, .jsx, .ts, .tsx
What suffixes do Jest test files commonly have?
.spec or .test
What are the names of files that Jest recognizes as test files?
Files called test.js or spec.js.
What is the purpose of the describe function in Jest?
To group linked behaviours and tests with a description string and a callback function.
What does the test function do in Jest?
It describes a specific behaviour being tested and contains assertions within a callback function.
What is the alias for the test function in Jest?
it
What happens to a test block when running a file with Jest?
It automatically passes unless an error is thrown inside it.
What is the purpose of Jest's assertion library?
To assert that the behaviour of a function is as expected.
What is the function of the expect statement in Jest?
To allow the use of semantic matcher functions to assert expected behaviour.
What does the matcher .toBe do in Jest?
Tests if two variables are the same.
What does the matcher .toEqual do in Jest?
Tests if two variables look the same.
What does the matcher .toContain do in Jest?
Tests if an array or iterable contains a given value.
What does the matcher .toMatchObject do in Jest?
Tests if an object contains given properties.
How can you negate expected behaviour in Jest?
By using the .not modifier with matchers.
What are Jest hooks used for?
To run actions before or after each test to maintain a sterile testing environment.
What is the purpose of beforeEach in Jest?
To register a function that runs before each test block.
What are the four types of Jest hooks?
beforeAll, beforeEach, afterEach, afterAll.
What are the seven primitive data types in JavaScript?
string, boolean, null, undefined, number, bigint, symbol.
How are primitive data types in JavaScript characterized?
They are fundamental data types from which more complex data structures are built.
Can variables in JavaScript be reassigned to different data types?
Yes, variables can be reassigned to hold a new value of any given data type at any point.
What is the type of the variable 'container' when it is assigned the value 'fruit'?
string
What happens to the type of 'container' when it is assigned the value 2?
It becomes a number.
What is the type of 'container' after it is assigned the value true?
boolean.
What does it mean that primitives are immutable in JavaScript?
Properties on primitive values cannot be created or overwritten.
What happens when you try to assign a property to a primitive value?
The write operation is ignored.
How are primitives compared in JavaScript?
Primitives are compared by value using the comparison operator ===.
What happens to variable 'a' and 'b' when 'a' is assigned the value 10 and then modified?
Variable 'a' becomes 20, while 'b' remains 10.
What distinguishes objects from primitives in JavaScript?
Objects are mutable, meaning their state or content can be updated.
What is the result of deleting a property from an object?
The property is removed and accessing it returns undefined.
How are objects stored in memory in JavaScript?
Objects are stored by reference, meaning they point to a specific address in memory.
What happens when two variables reference the same object?
Changes made to one variable will be reflected in the other.
What is the result of comparing two different object literals?
They are not equal because they reference different memory addresses.
What are arrays in JavaScript?
Arrays are a special type of object that are mutable and stored by reference.
What is the result of comparing two arrays that are identical in content but declared separately?
They are not equal because they reference different memory addresses.
What are some methods to create copies of objects in JavaScript?
Using a for loop, Array.prototype.slice(), or the spread operator.
What does the Jest assertion 'toBe' compare?
It compares the references of two arrays.
What does the Jest assertion 'toEqual' do?
It checks if the contents of two arrays are the same, including order.
What does 'deeply equal' mean in the context of Jest's 'toEqual'?
It means that the contents of the arrays are checked at every level of nesting.
Is there a native function in JavaScript to deeply check the contents of two objects?
No, you need to rely on third-party libraries for this functionality.
What is the purpose of the function createNewPeople?
To create a new array of objects with each age property replaced with a yearOfBirth property.
What does the test case 'returns a new array' check for in the createNewPeople function?
It checks that the output array is a different array from the input array.
Why is it important to ensure that createNewPeople does not mutate the input array?
To prevent unintended side effects that could alter the original input array.
What does the test case 'does not mutate the input array' verify?
It verifies that the contents of the input array remain unchanged after calling createNewPeople.
What is hoisting in JavaScript?
Hoisting is a feature where variable and function declarations are moved to the top of their scope by the JavaScript interpreter.
How does hoisting affect function declarations?
Function declarations are hoisted along with their definitions, allowing them to be called before their actual declaration in the code.
What happens when you try to call a function expression before its declaration?
It results in a ReferenceError because function expressions are not hoisted.
What is the Temporal Dead Zone in relation to let and const?
It is the period during which variables declared with let and const cannot be accessed until their declaration line is executed.
What error is thrown when trying to access a variable declared with const before its declaration?
A ReferenceError.
What does the console log output when a variable declared with var is accessed before its assignment?
It outputs 'undefined' instead of throwing a ReferenceError.
What is destructuring in JavaScript?
Destructuring is a syntax that allows unpacking values from arrays or object properties into individual variables.
How can object destructuring be used with a tutor object?
By using the syntax const { name, age } = tutor; to unpack properties into variables.
What is the result of using destructuring on the tutor object with the properties name and age?
name becomes 'David' and age becomes 31.
Can variable names be changed during object destructuring?
Yes, variable names can be changed for clarity or to avoid naming conflicts.