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 a = 3; | |
if (a < 2) { | |
console.log('is less than 2') | |
} |
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
{ | |
"name": "backend-for-dummies-examples", | |
"version": "1.0.0", | |
"main": "main.js", | |
"license": "MIT", | |
"dependencies": { | |
"typescript": "^3.1.4" | |
}, | |
"devDependencies": { | |
"ts-node": "^7.0.1", |
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
{ | |
"name": "backend-for-dummies-examples", | |
"version": "1.0.0", | |
"main": "main.js", | |
"license": "MIT", | |
"dependencies": { | |
"typescript": "^3.1.4" | |
}, | |
"devDependencies": { | |
"ts-node": "^7.0.1", |
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
console.log('Hello World') |
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 myAge: number = 20 | |
let myDescirption: string = 'Hello' | |
if (myAge > 0) { | |
myDescirption += ', I am ' + myAge.toString() | |
} else { | |
myDescirption += ', I have just been born' | |
} |
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
function isEven(num: number): boolean { | |
return num % 2 === 0 | |
} | |
isEven(20) // => true | |
isEven(11) // => false |
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 isPositive = function(value: number) : boolean { | |
return value > 0 | |
} | |
isPositive(1) // => true | |
isPositive(-20) // => false |
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
let comparison: boolean | |
comparison = 1 == true // => true | |
comparison = 1 === true // => false | |
comparison = 0 == false // => true | |
comparison = 0 === false // => false | |
comparison = '1' == 1 // => true | |
comparison = '1' === 1 // => false |
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 multiply = (factor1: number, factor2: number) : number => { | |
return factor1 * factor2 | |
} | |
multiply(1,2) // => 2 | |
multiply(3,4) // => 12 |
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 validateUser = (name?: string, email: string, password: string) => { | |
if (!name) { // if(name === undefined) { | |
throw new Error('invalid_name') | |
} | |
if (email.indexOf('@') -== -1) { | |
throw 'invalid_email' | |
} | |
if (password.length < 6) { |
OlderNewer