Java Script Flashcards

1
Q

What is a switch statement?

A

switch checks the variable for a comparison match on each case. They use strict equality Switch(varible){ case ‘A’ : ‘code to run’ break; case ‘B’: case ‘C’: default: ‘default case only runs if all other cases don’t match. }

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

What is block scope?

A

when the hierarchy with a block some method { inside, the bracket is a block of code. }

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

What is Global scope?

A

Global scope is the scope defined by the entire document. I.e the file is a block of code.

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

Should you use var to define a varible

A

Normally no. use let or const as they are defined by block scope.

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

function expression

A

function (){ does something };

expressions always have semicolons at the end!

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

How do create a function expression.

A

const name = function() { does something };

Has a semi colon at the end.

Function Expression is used inside the statement: let sayHi = …;, as a value. It’s not a code block, but rather an assignment. The semicolon ; is recommended at the end of statements, no matter what the value is. So the semicolon here is not related to the Function Expression itself, it just terminates the statement.

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

What is hoisting

A

Hoisting is JavaScript’s default behaviour of moving declarations to the top. a variable can be declared after it has been used variables defined with let and const are hoisted to the top of the block, but not initialized.

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

What does hoisting not do.

A

JavaScript only hoists declarations, not initializations.

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

Upon on the use of this. what does this refer to? return this.firstName + “ “ + this.lastName;

A

M - Method, this refers to the owner object. - M* - Methods like call(), and apply() can refer this to any object. A - Alone, this refers to the global object. F - In a function, this refers to the global object. - F* - In a function, in strict mode, this is undefined. E - Event, this refers to the element that received the event.

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

What is the global object

A

in a browser: it is the object [object Window]:

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

What is an expression in javascript

A

+ long a winded need to come back to

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

What is an argument in a function

A

it is the argument that is parsed let firstFucntion = function(parameter) { do something } firstFunction(‘hello’) – ‘hello’ is the argument

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

What is a parameter in a function?

A

it is the variable that is defined to have arguments parsed into it. let firstFucntion = function(parameter) { do something } firstFunction(‘hello’) – ‘hello’ is the argument

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

what do default values doe in a function

A

they assign values to the parameters if there are no arguments provided.

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

how do you create an arrow function?

A

const firstFunction = (prameter1, parameter 2 ) => { return something ; }; note if there is only one function and no need for return const firstFuntion = pramerter => something;

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

Difference between methods vs functions

A

methods invoke dot notation. they are invoked on an object or datatype e.g object.method()

17
Q

what is a call back function

A

is any executable code that is passed as an argument to other code; that other code is expected to call back (execute) the argument at a given time. This execution may be immediate as in a synchronous callback, or it might happen at a later time as in an asynchronous callback. Programming languages support callbacks in different ways, often implementing them with subroutines, lambda expressions, blocks, or function pointers

18
Q

what does forEach do

A

The forEach() method calls a function once for each element in an array, in order. takes 2 parameters, ( parameter, index )

19
Q

How do you do complex mathematical things in java script

A

Use the Math object that is built into java script

20
Q

What is a reference type

A

a reference type is

  • Object literals
  • Arrays
  • functions
  • Dates
    *
21
Q

What is a primitive type?

A

primitatve types are

  • numbers
  • strings
  • booleans
  • null
  • undefined
  • symbols

stored on the stack

22
Q

what is a reference type?

A

it is sat on the heap

  • object literals
  • Functions
  • dates
  • an
23
Q

what is the spread operator?

A

The spread syntax can be used when all elements from an object or array need to be included in a list of some kind. indicated by 3 dots

….

example

let numberStore = [0, 1, 2];

let newNumber = 12;

numberStore = […numberStore, newNumber];