You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
let & const are differnt ways of creating variable
const (constant values) let you create variable whose value is unchanged once provide.
let (variable values) let you create variable whose smiliar to var but with more secure scope.
functionmyFunc(){console.log("Its a normal function syntax in javascript); } const myFunc = () => { console.log("itsaarrowfunctionsyntaxinjavascript);}
More examples
// no argumentconstmyFunc=()=>console.log("Hi");//only one argumentconstmyFunc=name=>console.log(name);// two argumetsconstmyFunc=(name,age)=>{console.log(name,age);}// returning without writing return keywordconstmultiply=number=>number*2;console.log(multiply(2));
Exports & Imports (Modules)
// File name : person.jsconstperson={name: 'Sushil'}exportdefaultperson
// File name : utility.jsexportconstclean=()=>{....}exportconstbaseData=10;
// file name : app.js// default export : you choose the nameimportpersonfrom'./person.js'importprsfrom'./person.js'// named exportimport{baseData}from'./utility.js'import{clean}from'./utility.js'import{cleanasclr}from'./utility.js'import*asbundledfrom'./utility.js'
Classes
Blueprint of objects
Properties are like 'variables' attached to classes/ objects'
Methods are like 'functions attached to classes/ objects'
// ES6 SyntaxclassPerson{constructor(){this.myProperty='value'}myMethod(){console.log(this.myProperty);}}// ES7 -- updated (use this one)classPerson{myProperty='value';printGender=()=>{console.log(myProperty);}}
Rest: Used to merge a list of function arguments into an array
// unlimited amount of argumentsfunctionsortArgs(...args){returnargs.sort()}constfilter=(..args)=>{returnargs.filter(el=>el===1);}console.log(filter(1,2,3));
Destructuring
Easily extract array elements or object properties and store them in variables
Use Compiler (Next-Gen JavaScript) Babel + Presets
Use a Development Server
What Is React?
React is a declarative, efficient, and flexible JavaScript library for building user interfaces.
It lets you compose complex UIs from small and isolated pieces of code called "components".
We use components to tell React what we want to see on the screen. When our data changes, react will efficiently update
and re-render our components.
importReact,{Component}from'react';importReactDOMfrom'react-dom';classShoppingextendsComponent{render(){return(<divclassName="shopping-list"><h1>Shopping List for {this.prop.name}</h1><ul><li>Tomatoes</li><li>Mangoes</li><li>Spinach</li><ul></div>
);
}}
A ShoppingList is a React Component Class or React Component Type.
A component takes in parameters, called props (short for properties), and return a hierarchy of views to display
via the render method.
The render mwthod returns a description of what you want to see on the screen.
React takes the description and displays the result. In partcular, render returns a React element, which is
a lightweight descriptions of what to render.
Most React developers use a special syntax called "JSX" which makes these structure easier to write.
The <div /> syntax is transformed at build time to React.createElement('div').