Javascript Flashcards

1
Q

What does javascript do?

A

Browser receives html to render. Gets some script code, which executes JS. The script changes what we see on the screen

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

Ajax requests

A

Allows a website to communicate with a server asynchronously. I.e. we don’t have to re-render page url to see updates

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

Node

A

Allows us to use javascript on the backend.

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

object in Js

A

ruby equivalent of a key value hash

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

Constructor function

A

defines what our object looks like

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

.prototype

A

use it to define methods on a constructor form

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

new keyword

A

constant___proto === Obj(Like class on ruby).prototype

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

node

A

repl like pry for js

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

__proto__ vs .prototype

A

__proto is defined on the instance prototype on the object itself

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

closure

A

a function that uses a variable defined in before it

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

How JS Scope is defined

A

1 - Arguments
2 - Variables defined in the function
3 - Any variables that were already declared when function was defined (“free variables”)

Closure can also change variables defined before it

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

What is a callback

A

A function that is passed into another function as an argument with the intention of being called back at a later time

Common with asynchronous functions. Doesn’t require all functions to finish.

setTimeout

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

setTimeout

A

Defined globally

let callback = function() {
console.log("It has been 5 seconds!");
}

let timeToWait = 5000

global.setTimeout(callback, timeToWait);

global.setTimeout(function() {
console.log(“It has been 5 seconds!”);
}, 5000) ->ES5

global. setTimeout(() => console.log(“It has been 5 seconds”), 5000);
- > ES6 preferred syntax

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

callback vs. callback()

A

() passes in the return value not the invocation of the function

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

Expressions

A

line of code that returns a value. Needs a semi-colon at the end

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

Statement

A

Any line of code. Statements that aren’t expression do not require semi-colons

17
Q

{ curly braces }

A

Curly braces are used to delineate code blocks such as in function definitions, loops, and if blocks. Curly braces can also be used to define JavaScript objects.q

18
Q

NaN

A

Not a number. Property of the global object and is not a JS data type. NaN is the result of any illegal numerical operation

19
Q

What are the Falsey values in JS

A

zeros, empty strings, undefined, null, and NaN

20
Q

What is a primitive type

A

A primitive type is data that is not an object and cannot have methods.

Numbers are primitives and do not have object methods. So to do ruby like operation we need to call the Math object and pass in the number

21
Q

What are JS Objects

A

They can store both state (ruby instance variables) and behavior(ruby methods)

Objects are just a collection of associated properties and values. They are like hashes

In JavaScript, state and behavior of the object are treated the same way. Both are accessible as properties of the object.

In Ruby, state and behavior are separated into instance variables and methods which are accessed differently (ie. @ivar, vs self.method_name).

22
Q

Declaration

A

In JavaScript, in order to use a variable or constant, we must declare it by prepending the variable’s name with var, let, or const. Declaring a variable is the only way to introduce it to the environment.

23
Q

Return Values

A

Everything in javascript has a return value, even variable declarations and initializations. undefined is the default return value.

24
Q

Var

A

var is not the preferred means of declaring a variable in ES6. let or const are preferred.

25
Q

let

A

We can use let to declare block-scoped variables.

26
Q

Blocks

A

if statements, while llops, switch statements, for loops

27
Q

const

A

wConstants should be used for constructs that will not be re-declared or re-assigned. Properties:

  • block-scoped like let
  • Unlike Ruby constants, JavaScript will actually enforce constants by raising an error if you try to reassign them.
  • Trying to redeclare a constant with a var or let by the same name will also raise an error.\

Constants are not immutable. Only the binding is immutable. For example, if we set a constant equal to an object, we can still modify that object:

Constants cannot be reassigned but new constants of the same names can be declared in nested scopes.

28
Q

Declarations

A

Scoped to if blocks

29
Q

Globals

A

If you leave off a declaration when initializing a variable, it will become a global. Never do this.

30
Q

Function

A

Functions in JavaScript are just a special type of JS objects. In other words, you can do anything to a function that you can do to an object.

In Javascript, referencing the function name by itself will only return a pointer to the function; to execute it, you must invoke the function with arguments. If no arguments are required, this looks like () appended to the function name.