Skip to content

Instantly share code, notes, and snippets.

View jasminegmp's full-sized avatar

Jasmine jasminegmp

  • Orange County, California
View GitHub Profile
import React from 'react';
class Parent extends React.Component{
constructor(props){
super(props);
this.state = {
data: null
}
}
import React from 'react';
function Parent(){
const data = 'Data from parent';
return(
<div>
<Child dataParentToChild = {data}/>
</div>
)
}
import React from 'react';
class Parent extends React.Component{
constructor(props){
super(props);
this.state = {
data: 'Data from parent'
}
}
function myFunction(){
let a; // a's declaration is hoisted here, but remains uninitialized
a; // Will get a ReferenceError: Cannot access 'a' before initialization
console.log(a);
a = 'hello'; // everything above this line of code is referenced as temporal dead zone
}
myFunction();
function myFunction(){
let a; // a's declaration is hoisted here, but remains uninitialized
a // Will get a ReferenceError: Cannot access 'a' before initialization
console.log(a);
}
myFunction();
function myFunction(){
a;
console.log(a);
let a = 'hello';
}
myFunction();
var a = 'hi';
function myFunction(){
var a; // the a in the local scope is hoisted here and a is 'undefined
console.log(a); // outputs 'undefined
a = 'hello';
console.log(a); // outputs 'hello'
}
var a = 'hi';
function myFunction(){
console.log(a);
var a = 'hello';
console.log(a);
}
myFunction();
function myFunction(){
var localFunction = 'I see local';
console.log(localFunction);
}
myFunction(); // outputs 'I see functional scope'
console.log(localFunction); // Outputs an error 'localFunction is not defined'
let global = 'I see global.'
function scopeFunction(){
console.log(global);
}
scopeFunction(); // outputs 'I see global.'