Javascript Flashcards

(59 cards)

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
What question does scoping answer?
Where can we access a certain variable?
26
What is "Lexical Scoping"
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
What is the scope chain?
The scope chain is in what order you can access the variables in a particular scope. It only works from inside out.
28
What is the execution context?
It's the order in which functions are called | the start from the global and work inwards.
29
What is the 'This' Keyword?
It is a variable that each and every execution context gets.
30
What is method borrowing?
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
What is the DOM?
it stands for Document Object Model | And is a structured representation of html
32
What is the DOM used for?
It is used to connect webpages to scripts like javascript
33
What is the difference between classes and id's in html?
The classes can be used over and over, but the id's needs to be uniqe
34
How can you declare multiple variables in a clean way?
``` var scores = [1, 2]; var round = 0; ``` to var scores, round; scores = [1, 2]; round = 0;
35
How do you generate a random number?
you use the Math.random(); function for that.
36
How do you manipulate the DOM?
document.querySelector('class or id').somecontentMethod = variable
37
How do you read from the DOM?
You use the getElement, querySelector, elemenById methods
38
How do you change CSS styles with javascript?
you use the .style and the css method that you want to use ex display = 'none'
39
How do you change text in an html element?
you use the textContent method
40
How do you change text in an html element?
you use the textContent method
41
How do you change an html element?
You use the innerHtml method
42
How do you change an html element?
You use the innerHtml method
43
What are events?
Events are notifications that are sent to notify the code that something has happened on the webpage
44
How are event triggered?
Events are triggered by clicks, scrolling, pressing keys or resizing windows.
45
What are event listeners?
Event listeners are functions that perform an action based on a certain event, it waits for a specific event to take place.
46
How do you set up a event handler?
``` 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
What is a callback function?
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
What is an anonymous function?
Functions stored in variables do not need function names. They are always invoked (called) using the variable name. (a function without a name).
49
What is console.table ?
Console.table prints out a table of an object, making it more readable in the chrome console.
50
What is console.clear?
Console.clear clears out the chrome console
51
What is console.err
Console.err prints out an error message in the chrome console.
52
What is console.war
console.war prints out an warning message in the chrome console.
53
What is console.time and console.endTime ?
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
What can you have in an variable?
letters, numbers, _, and $ | Variables can not start with a number
55
What are the two main datatypes in JS?
Primitive Data types and Reference Data typers
56
What is Primitive Data Types?
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
What is Reference Data Types?
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
What is typeof?
typeof shows what kind of datatype a variable stores.
59
How can you convert a data type to a string in JS?
with the String method ex: let val = String(123); => '555' or with the toString method ex: let val = (5).toString(); => '5'