Intro Flashcards

1
Q

Where is the main place where javascript is used? What also?

A

In the web. business and even for games

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

What is typescript?

A

It is a superset of javascript (used for business)

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

What is necessary after cloning a javascript project?

A

npm install

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

What happens when you do a npm install?

A

the npm will install all “devDependencies” from packages.json

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

Where are the npm dependencies installed?

A

installed in the node_modules folder

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

How to start the web application?

A

npm run start

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

What happens when you save the file?

A

it refreshes the page

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

How to import javascript to the html?

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

Where to place a javascript file that can manipulate a website?

A

In the end of the html (but still above html tag)

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

Will spaces and tabs break the javascript?

A

No… it won’t matter.

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

How to see javascript errors?

A

In the inspect element, console tab.

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

What happens when an expection happens in the javascript file?

A

The javascript execution is halted

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

How to output logs to the browser?

A

Via the console.log(“my message”)

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

Is javascript case sensitive?

A

Yes.

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

How javascript methods are capitalized?

A

likeThisGotIt()

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

How to do single and multi line comment in javascript?

A

//single

/*
multi
line
*/

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

How to declare a variable? How it was declared in the past?

A

let = total 149.99;

it was declared as var in the past. DO NOT USE IT ANYMORE.

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

How to declare multiple variables?

A

With commas. e.g:

let price = 50,
     name = 'Name here';
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Can I start a variable that starts with a number?

A

No.

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

Should we use camelCase to declare variables? How do we start a variable that is internal?

A

Yes.. e.g: thisIsMy = ‘Var’; Internal/private vars start with _myPrivVar;

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

When start a variable with a $ sign?

A

Used only for auto-generated code.

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

Is it a good practice to always declare vars along with their values? What happens when you declare a var without initialization?

A

Yes. It becomes undefined.

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

Can a const variable change? Have we to set a value in the declaration?

A

No. Yes. e.g:

const price = 50;

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

What happens when we use a variable too soon (before declaration) using var and let?

A

var shows no error, becomes undefined. and let throws an error.

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

What are types and operators?

A

types are how the data is structured and operator is some sort of processing the types (e.g: + sign)

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

What does the typeof keyword does?

A

outputs the type of the variable, e.g: typeof price is integer.

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

How to do addition, subtraction, multiplication, division and remainder (modulus) in JS?

A

+, -, *, /, %

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

How to do a mathematical operation with the variables without retyping it?

A

price += 10;

note: works for all math operators.

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

How are the two ways to increment a value in js?

A

let price = 10;
++price
price ++
the last one is only executed AFTER it is called.

30
Q

What is operator precedence and where to find good information about it?

A

means that one operator is going to be executed before then others (e.g multiplication). See MDN (mozilla developer network), operator precedence page (the higher the number, the first it gets executed).

31
Q

How to escape a character in the string? Where to find the full information about escaping?

A

With backslash, e.g: “Hello "World"”; shows Hello “World”. See MDN for full description.

32
Q

How to do string interpolation in javascript?

A

Hello ${world}

33
Q

How to concatenate strings in js?

A

‘string’ + ‘ another string’

34
Q

How to convert a string to lowercase? Are other useful functions available the same way?

A
let m = 'ASD';
m.toLowerCase()

Yes. lots of other useful functions are there the same way.

35
Q

What is a NaN error? When it usually happen? When it is okay using a non-numerical value?

A

Not a Number. When you try to use a non-numerical variable as a numerical one. It is ok to use one when you put at the end of the numerical value. e.g: ‘123.12AAA’, aaa is not converted.

36
Q

How to express negation on javascript

A

with the exclamation !

37
Q

How to wipe a variable value? What about undefined?

A

with null… undefined is used for variables that were not initialized.

38
Q

How to declare an object in js?

A
let person = {
  name = 'foo',
  lastname= 'bar'
};
39
Q

How to check if a value is equal to other is js?

A

(‘A’ === ‘A’) returns true.

40
Q

What evaluates to false in js? What evaluates to true then?

A

false, 0, empty strings, null, undefined, NaN

evaluates to true everything NOT false (above).

41
Q

How to make a math operation become a object and then round it to two decimal places? How to convert it back to a number?

A

with parenthesis. e.g:
+(1.1 + 1.2).toFixed(2).
by starting with a plus sign

42
Q

how to write an else and else if?

A

if (false){} else {‘this executes’}

if (false){} else if (true) {‘this executes’}

43
Q

What is the difference between == and ===? Which one is recommended?

A

when == js will try to convert types and === is literal (compare types without conversion)

recommended always using === to avoid confusion

44
Q

How to declare a ternary operator (a.k.a three statements operator)?

A
let message = (price > 10) ? 'higher than 10' : 'lower or equal than 10'
condition ? true : false
45
Q

Can I use a declared let variable outside its block?

A

No… you’ll get a value is not defined error.

46
Q

how to declare a loop? while and do wile?

A
for (let i = 0; condition; i++){}
while (condition) {} 
do {} while (condition)
47
Q

how to declare a function?

A
function myFunc(myVar, myVar2) {
    return myVar + myVar2;
}
48
Q

What is a function expression? How to declare and call it?

A
To store a function in a variable. e.g:
let fn = function myFunc () {

}

fn()
//myFunc can't be called and is useful to have it there for debugging purposes.
49
Q

What happens when you don’t define arguments for all function parameters?

A

The missing parameter will become undefined.

50
Q

What happens when you use the return of a function that does not return anything?

A

It returns undefined.

51
Q

What happens when you declare a var with the same name in a function block?

A

It will be used instead of the other with higher scope.

52
Q

Is it possible to access an object property via string? If so, how?

A

Possible via person[‘age’] = 32

53
Q

How to declare a function within an object? How to access a property from the object within this method?

A

the declaration is below. to access internal props you need to call this.name

let person = {
  name = 'John',
  showName: function(){
    alert(this.name);
}
}
54
Q

What happens when you receive an object as a parameter and then change its properties?

A

It will change the objects contents to all places where the variable reference is used.

55
Q

Where to find the javascript built-in objects? What are four common examples?

A

In the MDN, built-in objects page. examples are:

Date, Math, String and Number.

56
Q

how to declare an array? How to initialize it?

A

let values = [ ];
let values = [1, 2, 3]; or
let values = Array.of(1, 2, 3);

57
Q

How to add values to the array in the beginning and in the end?

A

let values = [1, 2, 3];

values. push(4, 5); //4 and 5 goes to the end
values. unshift(0); //goes to the beginning

58
Q

How to remove an element from the end and from the beginning of the array?

A
let values = [1, 2, 3];
let lastItem = values.pop(); //removes and returns the last item from the array
let firstItem = values.shift(); //removes and returns the first item from the array
59
Q

What does the slice method do? What does the splice do?

A

It creates a copy of the array for the defined range. e.g: values.slice(0, 2) //0 until 1

splice does the same as slice but removes

60
Q

Does javascript functions contain a lot of overloads?

A

Yes, be aware that every single function can be called in a lot of different ways.

61
Q

how to make a copy of an array?

A

values.slice(); //no params

62
Q

how to search something in the array?

A

values.indexOf(‘asd’)

63
Q

what is a smart way to loop an array?

A

values.forEach(function(item){
console.log(item);
})

64
Q

What is global scope? What is a more strict scope?

A

global scope means a variable can be accessible from anywhere in the application. Function scope is a more strict manner to declare it.

65
Q

What is pollution of global scope?

A

when too many variables are declared there (bad thing)

66
Q

What is a common way to tackle global scope?

A
By using a global class, e.g: const app = {
   myglobalvar: 'asd'
}
67
Q

what is function scope?

A

it is variables that are accessible only within the function.

68
Q

What is Hoisting? How does javascript do Hoisting?

A

Is using something before it is declared in the source code… useful for functions, bad for var… use let instead.

Javascript does hoisting after passing twice in the source code… the first it collects functions and vars declarations and in the second it actually executes the code.

69
Q

Are global variables placed in the Window class? How to avoid it? What does it do to undeclared vars?

A

By declaring ‘use strict’ in the beginning of the javascript file. Now undeclared vars will throw errors.

70
Q

Is strict mode necessary for js modules?

A

No… it’s implicit.