This shows the execution order given JavaScript's Call Stack, Event Loop, and any asynchronous APIs provided in the JS execution environment (in this example; Web APIs in a Browser environment)
Given the code
const express = require('express'); | |
const app = express(); | |
function getPi() { | |
let sum = 0; | |
for (let n = 0; n < 10000000000; n++) { | |
let mult = n % 2 === 0 ? 1 : -1; | |
sum += mult * (1 / (2 * n + 1)); | |
} | |
return sum * 4; |
const express = require('express'); | |
const { Worker } = require('worker_threads'); | |
const app = express(); | |
app.get('/', function (req, res) { | |
const worker = new Worker(__dirname + '/worker.js', { | |
workerData: { ping: 'pong' }, | |
}); | |
worker.on('message', (pi) => { |
const Button = styled.button` | |
color: blue; | |
`; | |
const userQuery = gql` | |
{ | |
users { | |
firstName | |
} | |
} |
const generateIntro = (strings, ...values) => { | |
console.log(strings); // [ 'My name is ', ' and I am a ', '' ] | |
console.log(values); // [ 'Kannan', 'Javascript developer' ] | |
let str = ''; | |
strings.forEach((string, i) => { | |
str += string + (values[i] || ''); | |
}); | |
return str; | |
} |
const makeBold = (strings, ...values) => { | |
let str = ''; | |
strings.forEach((string, i) => { | |
str += `${string} ${values[i] ? `<strong>${values[i]}<strong>` : ''}`; | |
}); | |
return str; | |
} | |
const name = 'Kannan'; | |
const role = 'Javascript developer'; |
import { Test, TestingModule } from '@nestjs/testing' | |
import { INestApplication, LoggerService } from '@nestjs/common' | |
import * as request from 'supertest' | |
import { AppModule } from './../src/app.module' | |
class TestLogger implements LoggerService { | |
log(message: string) {} | |
error(message: string, trace: string) {} | |
warn(message: string) {} | |
debug(message: string) {} |
Picking the right architecture = Picking the right battles + Managing trade-offs
var udp = require('dgram'); | |
// --------------------creating a udp server -------------------- | |
// creating a udp server | |
var server = udp.createSocket('udp4'); | |
// emits when any error occurs | |
server.on('error',function(error){ | |
console.log('Error: ' + error); |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.