This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function debounce(fn, timer) { | |
let timeout; | |
return function(...arguments) { | |
clearTimeout(timeout); | |
timeout = setTimeout(() => { | |
fn.apply(this, arguments) | |
}, timer) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Singleton pattern | |
// SINGLEton. We use this design pattern when we only want a single instance of a class. | |
// That means we cannot create multiple instances - just one. If there is no instance, a new one is created. | |
// If there is an existing instance, it will use that one. | |
class Database { | |
constructor() { | |
this.connection = null; | |
} | |
static getDatabase() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let a ={} | |
let b = {key: 'b'} | |
let c = {key: 'c'} | |
a[b] = 78 | |
a[c] = 34 | |
console.log(a[b]) | |
--------------------------------------------------------------------------------------------------------------------------------------- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
process.nextTick(() => console.log(1)); | |
Promise.resolve().then(() => console.log(2)); | |
Promise.resolve().then(() => { | |
console.log(3); | |
process.nextTick(() => console.log(4)); | |
Promise.resolve().then(() => console.log(5)); | |
}).then(() => { | |
console.log(6); | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Promise.all | |
//will reject with this first rejection message | |
const p1 = new Promise((resolve, reject) => { | |
setTimeout(() => { | |
resolve("From Prmose1") | |
}, 1000) | |
}) | |
const p2 = "From Promise2" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let s = 'aaabbcddddswwaaaaa'; | |
let c = 1; | |
let data = [] | |
for (let i=0; i<s.length; i++) { | |
if (s[i] != s[i+1]) { | |
data.push(c); | |
data.push(s[i]); | |
c = 1; | |
} else { | |
c = c + 1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let a = 10; | |
let func = function (){ | |
let b = 20; | |
console.log("a and b is accessible (outer):", a, b); | |
let innerFunc= function (){ | |
var c = 30; | |
console.log("a and b and c is accessible (innner):", a, b, c); | |
let innerFunc1 = function() { | |
console.log('Parent variable can accessible') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Regular Function with "this" | |
function Car() { | |
this.speed = 0; | |
this.speedUp = function(speed) { | |
this.speed = speed; | |
// let self = this; ----> without line anonymous function take as shadow from speedUp function. | |
setTimeout(function () { | |
console.log(self.speed) | |
}, 100) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const express = require('express'); | |
const bodyParser = require('body-parser'); | |
const path = require('path'); | |
const app = express(); | |
app.use(bodyParser.json()); | |
app.use(bodyParser.urlencoded({extended: true})) | |
app.post('/upload-file', async function(req, res) { | |
const fileName = req.body.fileName; | |
const base64 = req.body.base64Data; |