Skip to content

Instantly share code, notes, and snippets.

@angelique-w
angelique-w / favorite-movie.js
Created September 23, 2019 08:43
Favorite Movie
const movieName = 'Legend';
const releaseYear = 2015;
const directorName = 'Brian Helgeland';
const message = movieName + ', réalisé par ' + directorName + ', est sorti en ' + releaseYear + '.';
alert(message);

Scope

Le scope correspond à la portée d’une variable.

On distingue :

  • le global scope : les variables déclarées en dehors d’un block et accessibles dans tout le programme (=> global variables)
  • le block scope : les variables déclarées dans un block (à l’intérieur de curly braces {}) sont accessibles uniquement dans ce block (=> local variables)

Scope pullution : phénomène qui se produit lorsque nous avons trop de global variables dans le global namespace ou lorsque nous réutilisons des variables dans différents blocs de portée.

process.stdin.resume()
process.stdin.setEncoding('utf8')
console.log('What\'s your age ? ')
process.stdin.on('data', age => {
const today = new Date();
const yearofBirth = today.getFullYear() - age;
console.log(((Number(age)) && (age <= 99) && (age < today)) ? `You were born in ${yearofBirth}` : 'The entry is incorrect')
process.exit()
})
class Person {
constructor(name, age) {
this.name = name;
this.age = age;
}
tellMyName() {
return `I am ${this.name}`;
}
tellMyAge() {
return `I am ${this.age} years old`;
const cowsay = require('cowsay');
console.log(cowsay.say({
text : "hello boy",
e : "oO",
T : "U "
}));
mysql> SELECT * FROM wizard WHERE birthday BETWEEN '1975-01-01' AND '1985-12-31';
+----+-----------+----------+------------+-------------+---------------------------------------+-----------+
| id | firstname | lastname | birthday | birth_place | biography | is_muggle |
+----+-----------+----------+------------+-------------+---------------------------------------+-----------+
| 1 | harry | potter | 1980-07-31 | london | | 0 |
| 2 | hermione | granger | 1979-09-19 | | Friend of Harry Potter | 0 |
| 4 | ron | weasley | 1980-03-01 | | Best friend of Harry | 0 |
| 5 | ginny | weasley | 1981-08-11 | | Sister of Ron and girlfriend of Harry | 0 |
| 6 | fred | weasley | 1978-04-01 | | | 0 |
| 7 | george | weasley | 1978-04-01 | |
mysql> INSERT INTO school (name, country, capacity) VALUES ('Beauxbatons Academy of Magic', 'France', 550), ('Castelobruxo', 'Brazil', 380), ('Durmstrang Institute', 'Norway', 570), ('Koldovstoretz', 'Russia', 125), ('Mahoutokoro School of Magic', 'Japan', 800), ('Uagadou School of Magic', 'Uganda', 350);
mysql> UPDATE school SET country='Sweden' WHERE id=3;
mysql> UPDATE school SET capacity=700 WHERE id=5;
mysql> DELETE FROM school WHERE name LIKE '%Magic%';
mysql> SELECT * FROM school;
+----+----------------------+----------+---------+
const http = require('http');
const url = require('url');
const port = 8000;
const requestHandler = (request, response) => {
console.log(request.url);
const parsedUrl = url.parse(request.url, true);
const parsedUrlQuery = parsedUrl.query;
console.log(parsedUrlQuery);
if (parsedUrlQuery.name && parsedUrlQuery.city) {
###
GET https://http-practice.herokuapp.com/wilders
Accept: application/json
###
GET https://http-practice.herokuapp.com/wilders?page=2&language=PHP
###
POST https://http-practice.herokuapp.com/wilders
Content-Type: application/x-www-form-urlencoded