This file contains 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
/** | |
Characteristics of Pure Function: | |
The return value of the pure functions solely depends on its arguments Hence, if you call the pure functions with the same set of arguments, you will always get the same return values. | |
They do not have any side effects like network or database calls | |
They do not modify the arguments which are passed to them | |
Characterisitcs of Impure functions |
This file contains 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 arr = [10, 12, 15, 21]; | |
for (var i = 0; i < arr.length; i++) { | |
(function(i){ | |
setTimeout(function() { | |
console.log('The index of this number is: ' + i); | |
}, 3000); | |
})(i) | |
} |
This file contains 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
<!--- | |
Event delegation in JS | |
Ref | |
https://medium.freecodecamp.org/3-questions-to-watch-out-for-in-a-javascript-interview-725012834ccb | |
--> | |
<html> | |
<body> | |
<ul id="todo-app"> |
This file contains 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
/** | |
parseInt("123hui") | |
returns 123 | |
Number("123hui") | |
returns NaN | |
parseInt("1.234334") | |
returns 1 | |
Number("1.234334") |
This file contains 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
/**These functions are implemented quite differently than dns.lookup(). They do not use getaddrinfo(3) and they always perform a DNS | |
query on the network. This network communication is always done asynchronously, and does not use libuv's threadpool. | |
Always use DNS.resolve it network operations | |
Dont use use DNS.lookup its uses the threadpool (Thread pool is limited)**/ |
This file contains 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
Provide a testing structure (Mocha, Jasmine, Jest, Cucumber) | |
Provide assertions functions (Chai, Jasmine, Jest, Unexpected) | |
Generate, display, and watch test results (Mocha, Jasmine, Jest, Karma) | |
Generate and compare snapshots of component and data structures to make sure changes from previous runs are intended (Jest, Ava) | |
Provide mocks, spies, and stubs (Sinon, Jasmine, enzyme, Jest, testdouble) | |
Generate code coverage reports (Istanbul, Jest, Blanket) | |
Provide a browser or browser-like environment with a control on their scenarios execution (Protractor, Nightwatch, Phantom, Casper) |
This file contains 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') | |
function readFile (filename) { | |
if (fs.existsSync(filename)) { | |
return fs.readFileSync(filename, 'utf8') | |
} | |
throw new Error('Cannot find file ' + filename) | |
} | |
describe('mocking individual fs sync methods', () => { |
This file contains 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
var http = require('http'); | |
var srvr = http.createServer(function (req, res) { | |
setTimeout(function(){ | |
res.write('Hello World!'); | |
res.end(); | |
}, 5000) | |
}); | |
srvr.listen(8080); |
This file contains 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
/* EXPRESS SETUP */ | |
const express = require('express'); | |
const app = express(); | |
const bodyParser = require('body-parser'); | |
app.use(bodyParser.urlencoded({ | |
extended: true | |
})); |
This file contains 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
var express = require('express'); | |
var cookieParser = require('cookie-parser'); | |
var session = require('express-session'); | |
var app = express(); | |
app.use(cookieParser()); | |
//For every request the session id is assigned if there is no session id | |
//We can attach fields in req.session.key = value pair | |
app.use(session({ |