Copyright(c) 2020-
Author: Chaitanya Tejaswi (github.com/CRTejaswi) License: GPL v3.0+
Personal notes for JS.
- Resources
- General
- CLI/GUI
- Structured Data (CSV, JSON, XML)
- Databases
- JS Engines
- SVG
- D3js
- Book: Learn ECMAscript (Prusty)
- Introduction
- Standard Library
- Functional Programming
- Asynchronous Programming
- Modular Programming
- API - Reflect
- API - Proxy
- Object-oriented Programming
- Web (DOM) Programming
- API - Storage
- Web/Service Workers
- Shared Memory & Atomics
- PWA https://www.youtube.com/playlist?list=PLNYkxOF6rcIB2xHBZ7opgc2Mv009X87Hh https://www.youtube.com/playlist?list=PLlyCyjh2pUe9RHFCJHU0kxpaivUzADPYk
- Projects
Link | Description |
---|---|
Projects | Useful list of projects |
- Access Environment Variables
Environment Variables can't be accessed in plain JS.
You can access User/System environment variables in NodeJS using dotenv package:This approach gets values from a file -require('dotenv').config(); console.log(process.env.Youtube_ApiKey); // <API_KEY>
.env
(and not from your PC). So, eh?!
- Using Object-Initialization
Explanation of code-snippet.
SYNTAX:
var obj = {
property(params) {...},
*generator(params) {...},
async property(params) {...},
async *generator(params) {...},
[property](params) {...},
*[generator](params) {...},
async [property](params) {...},
get property(){...},
set property(value){...}
};
var car1 = {
make: 'Honda',
model: 'City',
year: 2008
};
var car2 = {
make: 'Suzuki',
model: 'Wagon-R',
year: 2017
};
console.table([car1, car2]);
(index) make model year
0 Honda City 2008
1 Suzuki Wagon-R 2017
- Using A Constructor-Function
Explanation of code-snippet.
function Car(make, model, year){
this.make = make;
this.model = model;
this.year = year;
this.displayCar = displayCar;
};
function displayCar(){
var result = `A Beautiful ${this.year} ${this.make} ${this.model}`;
return result;
}
var car1 = new Car('Honda', 'City', 2008);
var car2 = new Car('Suzuki', 'Wagon-R', 2017);
console.log(car1.displayCar());
console.log(car2.displayCar());
A Beautiful 2008 Honda City
A Beautiful 2017 Suzuki Wagon-R
- Using
Object.create
Method
Explanation of code-snippet.
var Car = {
make: '',
model: '',
year: undefined
};
var car1 = Object.create(Car);
var car2 = Object.create(Car);
car1.make = 'Honda'; car1.model = 'City'; car1.year = 2008;
car2.make = 'Suzuki'; car2.model = 'Wagon-R'; car2.year = 2017;
console.table([car1, car2]);
(index) make model year
0 Honda City 2008
1 Suzuki Wagon-R 2017
- Using Object-Initialization
Explanation of code-snippet.
SYNTAX:
var obj = {
property(params) {...},
*generator(params) {...},
async property(params) {...},
async *generator(params) {...},
[property](params) {...},
*[generator](params) {...},
async [property](params) {...},
get property(){...},
set property(value){...}
};
- Iterator Protocol
let obj = {
array: [1,2,3,4,5],
nextIndex: 0,
next: function(){
return (this.nextIndex < this.array.length)
? {value: this.array[this.nextIndex++],
done: false}
: {done: true}
}
};
for (var i=0; i < 5; i++)
console.log(obj.next().value);
console.log(obj.next().done);
- Iterable Protocol
let obj = {
array: [1,2,3,4,5],
nextIndex: 0,
[Symbol.iterator]: function(){
return {
array: this.array,
nextIndex: this.nextIndex,
next: function(){
return (this.nextIndex < this.array.length)
? {value: this.array[this.nextIndex++],
done: false}
: {done: true}
}
}
}
};
let iterable = obj[Symbol.iterator]()
for (var i=0; i < 5; i++)
console.log(iterable.next().value);
console.log(iterable.next().done);
Outputs of both these code-snippets are:
1
2
3
4
5
true
-
Generator (Iterator + Iterable)
- Returns the next natural number
function* foo(n){
while (true)
yield ++n;
}
let generator = foo(0);
for (var i = 0; i < 10; i++)
console.log(generator.next().value);
var car1 = {
make: 'Honda',
model: 'City',
year: 2008
};
var car2 = {
make: 'Suzuki',
model: 'Wagon-R',
year: 2017
};
console.table([car1, car2]);
Promise.resolve(car1)
.then (function(value){
console.log(value.make, value.model, value.year);
console.log(value[0], value[1], value[2]);
console.log(value['make'], value['model'], value['year']);
});
Promise.reject(car2)
.then (null, function(value){
console.log(value.make, value.model, value.year);
console.log(value[0], value[1], value[2]);
console.log(value['make'], value['model'], value['year']);
});
(index) make model year
0 Honda City 2008
1 Suzuki Wagon-R 2017
Honda City 2008
undefined undefined undefined
Honda City 2008
Suzuki Wagon-R 2017
undefined undefined undefined
Suzuki Wagon-R 2017
Refer:
CSV
JSON
XML
-
IndexDB https://www.youtube.com/watch?v=pcelNF8Ckhk https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API https://developers.google.com/web/ilt/pwa/working-with-indexeddb
SpiderMonkey by Mozilla & V8 by Google are two major JS engines out there; both written in C/C++.
Install JS Shell Utility.
Also see Firefox: JS Interpreter
See Yulia Startsev's streams to get started with SpiderMonkey. Later on, decide which project to focus on.
Refer: Basics, Tutorial, Tutorial & Videos, SVG Elements.
Shapes
Tag | Attributes |
---|---|
<line> |
x1,y1,x2,y2 , stroke ,stroke-width , stroke-linecap , stroke-dasharray |
<polyline> |
points , fill , stroke ,stroke-width , stroke-linecap , stroke-dasharray |
<rect> |
x,y , width,height , fill , stroke ,stroke-width |
<polygon> |
|
<circle> |
cx,cy,r , fill , stroke ,stroke-width , stroke-dasharray |
<ellipse> |
cx,cy,rx,ry , fill , stroke ,stroke-width , stroke-dasharray |
<path> |
d (M-LQCA) , fill , stroke ,stroke-width , stroke-dasharray |
<text> |
x,y , fill , font , font-family , font-size |
<image> |
xlink:href , x,y , width,height , preserveAspectRatio |
<marker> |
id , refX,refY , viewBox , markerWidth,markerHeight , orient , preserveAspectRatio |
<path>
is the most important shape, with a curve sketched by M-LQCA
("Move to M(x,y), then move linearly/quadratically/cubically/on an ellipticalArc").
<path d="M 0,0 L 100,0" fill="none" stroke="#000000"/>
<path d="M 0,0 Q 150,200 100,100 z" fill="none" stroke="#ff0000"/>
<path d="M 0,0 C 150,200 150,150 100,100 z" fill="none" stroke="#00ff00"/>
<path d="M 0,0 A 150,200 0 0,0 100,100 z" fill="none" stroke="#0000ff"/>
Refer: Basics, Tutorial, Video, Videos, Examples.
- Live Server With Node, install/use live-server globally using:
npm install -g live-server
live-server
(currently lifted from https://github.com/tuvtran/project-based-learning#javascript)
- Build 30 things in 30 days with 30 tutorials
- Build an App in Pure JS
- Build a Jupyter Notebook Extension
- Build A Native Desktop App with JS
- Build a Progressive Web Application (PWA)
- How to Build a Web Framework in Less Than 20 Lines of Code
- Build Yourself a Redux
- How to write your own Virtual DOM
- Build A Realtime Serverless GraphQL API with WebSockets on AWS
Node
- Build A Simple Website With Node,Express and MongoDB
- Build a real-time Markdown Editor with NodeJS
- Test-Driven Development with Node, Postgres and Knex
- Write a Twitter Bot in Node.js
- Create A Simple RESTFUL Web App
- Build A Simple Search Bot in 30 minutes
- Build A Job Scraping Web App
React
- Create Serverless React.js Apps
- Create a Trello Clone
- Create a Character Voting App with React, Node, MongoDB and SocketIO
- React Tutorial: Cloning Yelp
- Build a Full Stack Movie Voting App with Test-First Development using Mocha, React, Redux and Immutable
- Build a Twitter Stream with React and Node
- Build a Serverless MERN Story App with Webtask.io
- Build A Simple Medium Clone using React.js and Node.js
- Integrate MailChimp in JS
- Build A Chrome Extension with React + Parcel
- Build A ToDo App With React Native
- Make a Chat Application
- Create a News App with React Native
- Learn Webpack For React
- Testing React App With Pupepeteer and Jest
- Build Your Own React Boilerplate
- Code The Game Of Life With React
- A Basic React+Redux Introductory Tutorial
- Build an Appointment Scheduler
- Build A Chat App with Sentiment Analysis
- Build A Full Stack Web Application Setup
- Create Todoist clone with React and Firebase
- Build A Random Quote Machine