Javascript Flashcards
You run the test and some functionality doesn’t work, how can you find out what is broken (without dev tools console)
I always look at the error message and what line of code fails in a stack trace
What is the difference between var, let, and const
Var: can declare, redeclare, assign, and reassign
Let: can declare, assign and reassign
Const: declare and assign in one line
var has global scope, let and const have local scope
How do you decide which variable to use ( var, let or const)
The rule of thumb is to go with const by default, unless it will need to be reassigned in the future, then I go with let. I don’t think I’ve used var in a while
Difference between forEach and map?
Map returns an array, forEach doesn’t return anything but it does execute a function for each element in the array
What is the difference an array and an object?
- An array is a sequenced list of values,
- while an object allows you to store key-value pairs and pull them not only by index as an array does but by name which makes it much faster and easier to find data in it
What are getters and setters?
Getters and setters are used for encapsulation, they allow you to prevent malicious or unintended changes
they are functions that allow you to get and set object values, respectively.
Why do you use Javascript?
It is one of the most popular languages in the world that is used pretty much in every type of programming - front-end, back-end, QA, data analytics, etc. It is easy to learn and is more flexible compared to other languages. Python is also a good candidate for UI and API test automation
What does it mean - import and export in JS?
Export: when you make a class, exporting it allows it be to be used in other modules
import: after you export a class, importing it allows you to use that class’s functionality
What is the difference between ‘forEach’ and a map in JS
Both are used to iterate over arrays
* forEach does not return a new array, rather it modifies the original array and returns undefined
* map returns a new array with the results of the function
if you need to change, alternate, or use the data, you should pick map because it returns a new array
What are regular functions and arrow functions in JS?
Regular
* use when you need the dynamic behavior of “this”, or when you need the “arguments” object
* They are suitable for methods in objects, event handlers, constructors, and situations where you want to dynamically bind “this”
Arrow functions allow us to write functions more concisely, but there are some drawbacks
* no ‘arguments’ object in arrow functions
* arrows do not create their own ‘this’ binding
* Arrow functions cannot be used as constructors
* arrow functions cannot be declared
What are the datatypes in JS
Num
String
BigInt
Boolean
Null
Undefined
Symbol
object
What is the difference between JS string interpolation and concatenation?
Concatenation:
* process of joining two or more strings together to create a new string
* used with the + operator
String interpolation:
* Process of embedding expressions or variables within a string literal to generate a new string
* used with backticks (`)
* inside template literals, you can embed variables directly using ${ }
It is better to use string interpolation as it allows for cleaner and easier to understand code
What is a property in a JS object?
It is a key-value pair associated with an object
- key
* string or symbol that uniquely identifies the property within an object
* aka property names
-value
* the value associated with the key
* it can be of any data type
What is an object in JS?
An object is a collection of properties, which are key-value associations. A property’s value can be a function, in which case it is called a method
What is an array in JS?
An array is a special type of object used to store multiple values in a single variable
* consists of an ordered list containing zero or more data types
* use numbered indices starting from 0 to access specific items
* arrays are dynamic in JS, they can be modified as needed
* contains elements of any data type