Functional stateless (dumb) React component
function Hello(props) {
return <div>Hello {props.name} </div>;
}
ES6+
const Hello = props => <div>Hello {props.name}</div>;
Functional stateless (dumb) React component
function Hello(props) {
return <div>Hello {props.name} </div>;
}
ES6+
const Hello = props => <div>Hello {props.name}</div>;
$ mkdir app
/* create app folder */$ cd app
/* move inside the app folder /
/$ npm init
/* create package.json */$ npm install express --save
/* install express.js locally */$ npm install
/* install requested modules */$ npm ls
/* [optinal] show a list of installed packages */var http = require('http'); | |
http.createServer(function (req, res) { | |
res.writeHead(200, { 'Content-Type': 'text/html' }); | |
res.end('<h1>Hello world!</h1>'); | |
}).listen(3000); | |
console.log('Server started on localhost:3000; press Ctrl-C to terminate....'); |
var http = require('http'); | |
http.createServer(function (req, res) { | |
// normalize url by removing querystring, optional | |
// trailing slash, and making it lowercase | |
var path = req.url.replace(/\/?(?:\?.*)?$/, '').toLowerCase(); | |
switch (path) { | |
case '': | |
res.writeHead(200, { 'Content-Type': 'text/html' }); | |
res.end('<h1>Homepage</h1>'); |
function isEven(a) { | |
if (a < 0) a = -a; | |
if (a == 0) return true; | |
if (a == 1) return false; | |
return isEven(a - 2) | |
} |
var log = console.log; | |
var number = 8; | |
var line = " "; | |
var counter = 0, counter2 = 0; | |
while (counter < number-1) { | |
counter++; | |
line = counter % 2 ? " " : "#"; | |
counter2 = 0; | |
while (counter2 < number-1) { | |
var letter = (line[counter2] == " ") ? "#" : " "; |
function remove(array, index) { | |
return array.slice(0, index).concat(array.slice(index + 1)); | |
} | |
Array.prototype.remove = function (index) { | |
return this.slice(0, index).concat(this.slice(index + 1)); | |
} | |
//random 0 or 1: | |
Math.floor(Math.random()+0.5) |
var obj = { | |
a: "a", | |
b: "b", | |
c: [0, 1, 2] | |
} | |
for (var key in obj) { | |
if (obj.hasOwnProperty(key)) { | |
console.log(key + ': ' + obj[key]); | |
} |
var DATA = []; //or {} | |
//universal javascript module | |
// This makes sure the data is exported in node.js | |
// `require('./{your_path}/data.js')` will get your data: | |
if (typeof module != "undefined" && module.exports) { | |
module.exports = DATA; | |
} |
//returns array which includes all numbers from start to end (included) | |
function range(start, end, step) { | |
if(step < 0) step = -step; | |
if(!step) step = 1; | |
if(end == undefined) { | |
end = start; | |
start = 0; | |
} | |
var result = []; |