Java Script Flashcards
What is a switch statement?
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. }
What is block scope?
when the hierarchy with a block some method { inside, the bracket is a block of code. }
What is Global scope?
Global scope is the scope defined by the entire document. I.e the file is a block of code.
Should you use var to define a varible
Normally no. use let or const as they are defined by block scope.
function expression
function (){ does something };
expressions always have semicolons at the end!
How do create a function expression.
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.
What is hoisting
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.
What does hoisting not do.
JavaScript only hoists declarations, not initializations.
Upon on the use of this. what does this refer to? return this.firstName + “ “ + this.lastName;
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.
What is the global object
in a browser: it is the object [object Window]:
What is an expression in javascript
+ long a winded need to come back to
What is an argument in a function
it is the argument that is parsed let firstFucntion = function(parameter) { do something } firstFunction(‘hello’) – ‘hello’ is the argument
What is a parameter in a function?
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
what do default values doe in a function
they assign values to the parameters if there are no arguments provided.
how do you create an arrow function?
const firstFunction = (prameter1, parameter 2 ) => { return something ; }; note if there is only one function and no need for return const firstFuntion = pramerter => something;
Difference between methods vs functions
methods invoke dot notation. they are invoked on an object or datatype e.g object.method()
what is a call back function
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
what does forEach do
The forEach() method calls a function once for each element in an array, in order. takes 2 parameters, ( parameter, index )
How do you do complex mathematical things in java script
Use the Math object that is built into java script
What is a reference type
a reference type is
- Object literals
- Arrays
- functions
- Dates
*
What is a primitive type?
primitatve types are
- numbers
- strings
- booleans
- null
- undefined
- symbols
stored on the stack
what is a reference type?
it is sat on the heap
- object literals
- Functions
- dates
- an
what is the spread operator?
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];