Javascript Flashcards

1
Q

What is Javascript

A

Js is a programming language that is

  • lightweight
  • cross platform
  • object oriented
  • one of three core technologies
  • commonly used in webpages
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Can you use js in the server end?

A

Yes with node.js

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

How do you add js to a webpage?

A

you either add the code in a script tag in the html file

or you create a new js file and add a script source in the html
ex

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

what is a variable?

A

A variable is a container in which we can store values

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

how do you declare variables in js?

A

var name = ‘Name’;

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

What are datatypes?

A

there are different types of values

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

What kind of datatypes are there in js?

A
  • numbers( always have floats)
  • strings
  • booleans
  • Undefined(datatype that does not have a value yet)
  • Null (non existent)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is dynamic typing?

A

Dynamic typing means that js understands what kind of datatype you are working with.

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

How do you comment out code in javascript?

A
  • single line comment //

- multiline comment /* stuff */

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

What is type coercion?

A

Type conversion means that javascript will transform the datatype to another by itself

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

Can we declare a variable without declaring a value to that?

A

Yes that is possible in javascript, the output will be shown as “undefined”.

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

What is a variable mutation?

A

Variable mutation is when we assign variables new values.

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

What is the difference between arguments and parameters?

A

Argument is what the user passes in when the function is called.
A parameter is the placeholders for arguments in the function.

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

How do you call a function in Javascript?

A

var someThing = function(argument);

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

How do you write function statements?

A
function someFun(parameter {
  //code
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How do you write a function statement?

A
var someFun = function(parameter) {
  // code
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is the difference between a function expression and a function statement?

A

A function statement performs an action

A function expression produces a value

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

How do you create an array in js?

A
var name = ['john', 'jane', 'mark']
or
var years = new Array(1990, 1999, 1948)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

How do you get an object from an array?

A

names[0];

index in js are zero based (the start from zero)

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

What are some array functions?

A

.push(‘something’); adds an element in the end

.unshift(‘something’); adds an object in the beginning

.pop( ); deletes the last element

.shift( ); deletes the first element

.indexOf(‘something’); shows the index of that element in an array

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

What are objects in js?

A

objects are key value pairs

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

What is a for loop?

A

the for loop loops through a block of code a number of times.

the for loop is the most used loop in javascript
for (var i = 0; 1 < 20; i++) {
console.log(i);
}

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

what is the .length method?

A

the lenght method tells us how many elements there are in an array.

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

What is a while loop?

A
The while loop runs a block of code while the condition is true.  
var i = 0;
while( i < names.lenght) {
  console.log(names[i]);
}
25
Q

What question does scoping answer?

A

Where can we access a certain variable?

26
Q

What is “Lexical Scoping”

A

A function that is lexically within another function gets access to the scope of the outer function. Basically gets access to the variable for the parent scope

27
Q

What is the scope chain?

A

The scope chain is in what order you can access the variables in a particular scope.
It only works from inside out.

28
Q

What is the execution context?

A

It’s the order in which functions are called

the start from the global and work inwards.

29
Q

What is the ‘This’ Keyword?

A

It is a variable that each and every execution context gets.

30
Q

What is method borrowing?

A

It’s when you use another function to define a variable instead of creating a new one.

ex
mike.calculateAge = john.calculateAge

Where the function calculateAge is defined inside the john object.

31
Q

What is the DOM?

A

it stands for Document Object Model

And is a structured representation of html

32
Q

What is the DOM used for?

A

It is used to connect webpages to scripts like javascript

33
Q

What is the difference between classes and id’s in html?

A

The classes can be used over and over, but the id’s needs to be uniqe

34
Q

How can you declare multiple variables in a clean way?

A
var scores = [1, 2];
var round = 0;

to

var scores, round;
scores = [1, 2];
round = 0;

35
Q

How do you generate a random number?

A

you use the Math.random(); function for that.

36
Q

How do you manipulate the DOM?

A

document.querySelector(‘class or id’).somecontentMethod = variable

37
Q

How do you read from the DOM?

A

You use the getElement, querySelector, elemenById methods

38
Q

How do you change CSS styles with javascript?

A

you use the .style and the css method that you want to use ex display = ‘none’

39
Q

How do you change text in an html element?

A

you use the textContent method

40
Q

How do you change text in an html element?

A

you use the textContent method

41
Q

How do you change an html element?

A

You use the innerHtml method

42
Q

How do you change an html element?

A

You use the innerHtml method

43
Q

What are events?

A

Events are notifications that are sent to notify the code that something has happened on the webpage

44
Q

How are event triggered?

A

Events are triggered by clicks, scrolling, pressing keys or resizing windows.

45
Q

What are event listeners?

A

Event listeners are functions that perform an action based on a certain event, it waits for a specific event to take place.

46
Q

How do you set up a event handler?

A
step 1 select the element in which the event will occur
like button class
step 2 add the event listner method .addEventListener
step 3 add two arguments, the event like click and the function that should start
47
Q

What is a callback function?

A

A callback function is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action.

48
Q

What is an anonymous function?

A

Functions stored in variables do not need function names. They are always invoked (called) using the variable name.
(a function without a name).

49
Q

What is console.table ?

A

Console.table prints out a table of an object, making it more readable in the chrome console.

50
Q

What is console.clear?

A

Console.clear clears out the chrome console

51
Q

What is console.err

A

Console.err prints out an error message in the chrome console.

52
Q

What is console.war

A

console.war prints out an warning message in the chrome console.

53
Q

What is console.time and console.endTime ?

A

It shows how long it takes for the code between the console.time and console.endTime to execute with a numerical value in the chrome console.

54
Q

What can you have in an variable?

A

letters, numbers, _, and $

Variables can not start with a number

55
Q

What are the two main datatypes in JS?

A

Primitive Data types and Reference Data typers

56
Q

What is Primitive Data Types?

A

They are stored directly in the location the varible accesses (Stored on the Stack)

Boolean.
Null.
Undefined.
Number.
String.
Symbol (new in ECMAScript 6)
57
Q

What is Reference Data Types?

A

They are acessed by reference, Objects that are stored on the heap
A pointer to a location in memory

Arrays
Object literals
Functions
Dates

58
Q

What is typeof?

A

typeof shows what kind of datatype a variable stores.

59
Q

How can you convert a data type to a string in JS?

A

with the String method
ex:
let val = String(123);
=> ‘555’

or

with the toString method
ex:
let val = (5).toString();
=> ‘5’