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;