JS Fundamentals Flashcards
ES5 supports the following data types
number, string, Boolean and undefined
ES5 uses ____ to declare a variable
var
ES5 cannot import ____ into another file
JSX
ES5 uses the _____ module to include a react module or component
RequireJS module
ES5 uses the RequireJS module to include a react module or component
ES5 uses ____ syntax
ES5 uses function(){} syntax
ES5 props are…
ES5 props are implicitly defined and we add this
to functions
ES5 doesn’t require a ____ to render in the web
a transpiler like Babel
ES6 supports the following data types:
number, string, boolean, undefined and Symbol
ES6 uses the following to declare a variable
var, let and const
ES6 can import a ____ file to another file
JSX
ES6 can import a JSX file to another file
ES6 uses the ____ to include a react module or component
import module
ES6 uses the import module to include a react module or component
ES6 uses ____ function syntax
arrow function
ES6 uses arrow function syntax
ES6 props are passed ____ though a ____
We _____ bind ____ to ____ in the ____
ES6 props are passed EXPLICITLY though a CONSTRUCTOR
We EXPLICITLY bind this
to functions in the constructor
ES6 requires a ____ like babel
ES6 requires a transpiler like babel
What are the different primitive data types in JS?
string, number, BigInt, Boolean, undefined, null, Symbol
What are the different non-primitive data types in JS?
stores multiple and complex values
String
Can be represented using a single or double quote
Number
Can be written with or without decimals
BigInt
Stores numbers about the limitation of Number type
boolean
only has two values true or false
undefined
when a variable is declared but not assigned
null
a non-existent or invalid value
Symbol
ES6 data type that stores anonymous and unique property keys
Can create a global Symbol by using the methods Symbol.for() or Symbol.keyFor()
Object
can store data in key/value pairs
can store arrays
can store functions
hoisting
default behavior of javascript where all variable and function declarations are moved on top.
difference between == and === operators
==
compares values
===
compares value and types
implicit type coercion
automatic conversion of value from one data type to another
types of coercions
string, boolean, logical, equality
string coercion
takes place using the + operator. When a number is added to a string, the return value is always a string type because JS converts the number to a string type before performing the operation
var x = 3 var y = "3" x + y // Returns "33"
boolean coercion
occurs in logical operators, ternary operators, if statements and loop checks
equality coercion
takes place when using == operator because == compares values and not types
is JS statically typed or dynamically typed
Dynamically typed. the type of a variable is checked during run-time in contrast to a statically typed language, where the type of a variable is checked during compile-time
characteristics of static typing
variables have types
values have types
variables cannot change type
characteristics of dynamic typing
variables have no types
values have types
variables change type dramatically (ie type coercion)
Immediately Invoked Function (IIFE, pronounced IFFY)
a function that runs as soon as it is defined
(function(){ // do something })()
Higher Order Functions
Functions that operate on other functions by taking a function as an argument or returning a function
function higherOrder(fn) { fn() } higherOrder(function() { console.log("Hello world") })
this
the object that is a property of a function
call()
method used to call a function
function doSomething(){ console.log("hi") } doSomething.call()
apply()
method used to call a function. The difference is that apply takes arguments as an array
function sendMessage(message) { return this.name + "is" + message } var person4 = { name: "John" } sendMessage.apply(person4, ["welcome"])
bind()
returns a new function where this is bound to the owner object, which is provided as the parameter
currying
a function that accepts arguments that are transformed into functions
// Noncurried version
const add (a,b,c) => {return a + b + c }
console.log(add(2,3,5)) // 10
~~~
// Curried version const addCurry = (a) => { return (b) => { return (c) => { return a + b + c } } } console.log(addCurry(2)(3)(5)) // 10
~~~
three types of scopes in JS:
- global
- local or function
- block scope
global scope
code that’s accessible from anywhere inside the code
function scope
code that’s accessible from anywhere inside the function
block scope
variables declared inside of a block ( such as {})
Object prototypes
All objects inherit properties from a prototype.
I.e, (Date, Math, Array, etc)
callback
functions that are used as an argument to another function
memoization
a form of caching where the return value is cached based on the parameters. If the parameter is not changed, the cached value is returned
recursion
when a function repeatedly calls itself until it arrives at a result
rest parameter
indicates there’s an unknown number of parameters in an argument. Must be used as the last parameter of an argument
spread operator
used to spread arrays or objects
JS classes
syntactic sugar for constructor functions
Before we would
```jsx
function Student(name){
this.name=name
}
~~~
Now
```jsx
class Student {
constructor(name) {
this.name = name
}
}
~~~
temporal dead zone
the state where variables are unreachable at the time they are called or used
```jsx
x = 23 // Gives reference error
let x;
~~~