Javascript Flashcards

1
Q

You run the test and some functionality doesn’t work, how can you find out what is broken (without dev tools console)

A

I always look at the error message and what line of code fails in a stack trace

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

What is the difference between var, let, and const

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you decide which variable to use ( var, let or const)

A

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

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

Difference between forEach and map?

A

Map returns an array, forEach doesn’t return anything but it does execute a function for each element in the array

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

What is the difference an array and an object?

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are getters and setters?

A

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.

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

Why do you use Javascript?

A

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

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

What does it mean - import and export in JS?

A

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

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

What is the difference between ‘forEach’ and a map in JS

A

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

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

What are regular functions and arrow functions in JS?

A

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

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

What are the datatypes in JS

A

Num
String
BigInt
Boolean
Null
Undefined
Symbol
object

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

What is the difference between JS string interpolation and concatenation?

A

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

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

What is a property in a JS object?

A

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

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

What is an object in JS?

A

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

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

What is an array in JS?

A

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

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

What kind of array methods do you know?

A
  • push() - adds one or elements to the end of an array
  • pop() - removes the last element from an array and returns that element
  • shift() - removes the first element from an array and returns that element
  • unshift() - adds one or more elements to the beginning of an array
  • slice() - changes the contents of an array by removing or replacing existing elements and/or adding new elements in place
  • concat() - combines two or more arrays
  • forEach() - executes a function once for each array element
  • map() - creates a new array with the results of calling a function on every element in the calling array
  • filter() - iterates over an array and returns a new array with values that match specified conditions
17
Q

What does the substring() method do?

A

returns the part of the string from the start index up and excluding the end index, or just the end if the end index is not specified

18
Q

What is the difference between ‘==’ and ‘===’?

A

== checks for loose equality. If the datatypes of operands are different, the engine will convert one of them to be the same as the other

=== checks for strict equality. Engine will not perform datatype conversion

19
Q

What is a conditional/ternary operator?

A

It is the JS operator that takes three operands:
* a condition followed by a question mark
* an expression to execute if the condition is truth
* another expression if the condition is falsy

Can be used as a more concise alternative to an if-else statement

20
Q

What are the differences between local and global variables?

A

local
* Declared within a function or a block
* they are encapsulated within their containing function or block, cannot be accessed from outside the function or block

global
* declared outside of any function or block
* can be accessed from anywhere within the program

It is better to use local variables as much as possible to avoid possible naming conflicts and to encapsulate data and reduce dependencies between different parts of the code

21
Q

What is the difference between an array and object?

A

The main difference is the way their properties are accessed.
* The properties of an object are accessed using their name
* The elements of an array are accessed using their index

22
Q

What commands are you using for git?

A

git checkout - creates branches and helps to navigate between them
* git add - add files to the staging area
* git pull - pull a copy of the current branch from the repo and immediately merge it into the local copy
* git branch - list all the branches in your repo and tells you what branch you’re currently in
* git push - push from local branch to origin
* git commit - will create a snapshot of the changes and save it to the git directory

23
Q

What is the difference between Git and GitHub?

A

Git is the system that takes care of the project history
* version control system for tracking changes in code
* installed in local machine

GitHub is an online repository hosting platforms using Git
* cloud based service that hosts git repositories