Basic JS Flashcards

1
Q

Javascript is dynamically typed, what does that mean?

A

We can put any type in a variable. For example, a variable can at one moment be a string and then store a number:

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

What does the number type represent?

A

Both integer and floating point numbers.

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

Besides regular numbers, there are so-called “special numeric values” which also belong to the number data type, what are they ?

A

Infinity, -Infinity and NaN.

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

NaN is sticky. What does that mean?

A

Any further mathematical operation on NaN returns NaN:

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

What is the largest value the “number” type can safely represent?

A

((2^53)-1)

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

BigInt type was recently added to the language to represent integers of arbitrary length. How do you define a BigIng value?

A

A BigInt value is created by appending n to the end of an integer.

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

What can we do with backticks in Javascript?

A

Backticks are “extended functionality” quotes. They allow us to embed variables and expressions into a string by wrapping them in ${…}.

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

Is there a char in Javascript?

A

No, There is no character type.

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

What type does the null value belong to ?

A

It forms a separate type of its own which contains only the null value:

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

What is the meaning of null ?

A

It’s just a special value which represents “nothing”, “empty” or “value unknown”.

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

What is the meaning of undefinedl ?

A

The meaning of undefined is “value is not assigned”. If a variable is declared, but not assigned, then its value is undefined:

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

What is the The typeof operator and what does it do ?

A

The typeof operator returns the type of the operand. It’s useful when we want to process values of different types differently or just want to do a quick check.

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

What happens when we try to concatenate a string and a number?

A

You might expect this to return an error, but it works just fine. How numbers should be displayed as strings is fairly well-defined, so the browser automatically converts the number to a string and concatenates the two strings.

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

If we have a numeric variable that we want to convert to a string, we can use ?

A

The String() function converts its argument to a string.

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

If we have a string that we want to convert to a numeric variable, we can use ?

A

The Number() function converts anything passed to it into a number, if it can.

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

The length property returns ?

A

The length of a string

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

There are 3 methods for extracting a part of a string, what are they ?

A

slice(start, end)
substring(start, end)
substr(start, length)

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

How do open dev tools on keyboard?

A

opt, commmand, c

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

What are return values?

A

The values that a function returns when it completes

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

What are parameters,in Javascript functions?

A

In JavaScript, parameters are the items listed between the parentheses in the function declaration.

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

What are arguments, in Javascript functions?

A

Function arguments are the actual values we decide to pass to the function.

22
Q

How is a function build up?

A

The function keyword goes first, then goes the name of the function, then a list of parameters between the parentheses (comma-separated, empty in the example above, we’ll see examples later) and finally the code of the function, also named “the function body”, between curly braces.

23
Q

What does a function with an empty return or without returns, return?

A

Undefined

24
Q

Never add a newline between return and the value, why?

A

because JavaScript assumes a semicolon after return

25
Q

One function – one action

A

A function should do exactly what is suggested by its name, no more.

26
Q

What is a Function Expression?

A

a function, created inside an expression or inside another syntax construct.

It allows us to create a new function in the middle of any expression.

27
Q

In JavaScript, a function is a value

A
28
Q

What is a callback function?

A

The idea is that we pass a function and expect it to be “called back” later if necessary.

29
Q

When is a function expression created?

A

A Function Expression is created when the execution reaches it and is usable only from that moment.

30
Q

When can we call a function declaration ?

A

Always, A Function Declaration can be called earlier than it is defined.

31
Q

Another special feature of Function Declarations is their block scope. What is that ?

A

n strict mode, when a Function Declaration is within a code block, it’s visible everywhere inside that block. But not outside of it.

32
Q

How do arrow functions look like?

A

let func = (arg1, arg2, …, argN) => expression;

33
Q

What is a call stack?

A

A call stack is a way for the JavaScript engine to keep track of its place in code that calls multiple functions. It has the information on what function is currently being run and what functions are invoked from within that function

34
Q

The call stack works based on the WHICH principle?

A

The call stack works based on the last-in-first-out (LIFO) principle.

35
Q

What is A ReferenceError?

A

A ReferenceError is thrown when one refers to a variable that is not declared and/or initialized within the current scope.

36
Q

What is a Syntax error?

A

A syntax error occurs when the code you are trying to run is not written correctly, i.e., in accordance with the grammatical rules of JavaScript.

37
Q

When is a Type error thrown ?

A

an operand or argument passed to a function is incompatible with the type expected by that operator or function;
or when attempting to modify a value that cannot be changed;
or when attempting to use a value in an inappropriate way.

38
Q

What is the DOM ?

A

The DOM (or Document Object Model) is a tree-like representation of the contents of a webpage - a tree of “nodes” with different relationships depending on how they’re arranged in the HTML document.

39
Q

What selectors could I use to refer to <div class="display"></div>?

A

div.display
.display
#container > .display
div#container > div.display

40
Q

What does element.querySelector(selector) do ?

A

returns a reference to the first match of selector.

41
Q

What does element.querySelectorAll(selectors) do ?

A

returns a “nodelist” containing references to all of the matches of the selectors.

42
Q

What is a callback?

A

Callbacks are functions that are passed into another function as an argument.

42
Q

Arrow Functions are shorter way to write a function. What are the rules of arrow functions ?

A

If there is only one argument, the parenthesis () can be omitted
if arrow functions are one line, the brackets {} can be omitted.
When omitting the brackets, the arrow function returns the evaluated expression without requiring the return keyword.

43
Q

Shorten this with the arrow function rules :

const playThe = (funky) => {
return funky + “ music”;
}

A

const playThe = funky => funky + “ music”;

44
Q

How to switch branches on git?

A

git checkout <branch_name></branch_name>

44
Q

How to make a new branch on git?

A

git branch <branch_name></branch_name>

45
Q

How to create a new branch and switch right to it ?

A

git checkout -b <branch_name></branch_name>

46
Q

How to see all current branches?

A

git branch

47
Q

How to go back to main branch ?

A

git checkout main

48
Q

How to merge ?

A

git merge <branch_name> which will take the changes you’ve committed in branch_name and add them to the branch that you’re currently on.</branch_name>

49
Q
A
50
Q
A