@zachfedor
https://slides.com/zachfedor/js-101
"Learning JavaScript used to mean you weren't a serious software developer. Today, not learning Javascript means the same thing."
- Tim O'Reilly
// Hey. I'm a Program!
console.log("Hello World!");
// Variables
var a = 2;
var b = "string";
var c = a + b; // "2string"
// Function
function factorial(n) {
if (n === 0 || n === 1) {
return 1;
}
return n * factorial(n - 1);
}
factorial(3); // returns 6
// This is the client-side script.
// Initialize the HTTP request.
var xhr = new XMLHttpRequest();
xhr.open('get', 'send-ajax-data.php');
// Track the state changes of the request.
xhr.onreadystatechange = function () {
var DONE = 4; // readyState 4 means the request is done.
var OK = 200; // status 200 is a successful return.
if (xhr.readyState === DONE) {
if (xhr.status === OK) {
// 'This is the returned text.'
console.log(xhr.responseText);
} else {
// An error occurred during the request.
console.log('Error: ' + xhr.status);
}
}
};
// Send the request to send-ajax-data.php
xhr.send(null);
// This is beauty of jQuery
$.get('send-ajax-data.php')
.done(function(data) {
console.log(data);
})
.fail(function(data) {
console.log('Error: ' + data);
});
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World\n');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
encapsulates common application functionality
packages of code used by your application to perform a task
https://slides.com/zachfedor/js-101