Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
var hello = "Hello";
var world = "World";
// Message equals "Hello World"
var message = hello + " " + world;while(condition){
// do it as long as condition is true
}var i = 0, x = "";
while (i < 5) {
x = x + "The number is " + i;
i++;
}do {
// code block to be executed
} while (condition);// Single quotes can be used
var str = 'Our lovely string';
// Double quotes as well
var otherStr = "Another nice string";"中文 español English हिन्दी العربية português বাংলা русский 日本語 ਪੰਜਾਬੀ 한국어";// Just use the property .length
var size = 'Our lovely string'.length;// This is an array of strings
var fruits = ["apple", "banana", "pineapple", "strawberry"];
// We set the variable banana to the value of the second element of
// the fruits array. Remember that indices start at 0, so 1 is the
// second element. Result: banana = "banana"
var banana = fruits[1];var myPrimitive = "first value";
myPrimitive = "another value";
// myPrimitive now points to another string.
var myObject = { key: "first value"};
myObject.key = "another value";
// myObject points to the same object.var array = [1 , 2, 3];
// Result: l = 3
var l = array.length;"Hello World"// This is a float:
var a = 1.2;
// This is an integer:
var b = 10;var a = 2;
var b = a;var country = 'France';
var weather;
var food;
var currency;
if(country === 'England') {
weather = 'horrible';
food = 'filling';
currency = 'pound sterling';
}
if(country === 'France') {
weather = 'nice';
food = 'stunning, but hardly ever vegetarian';
currency = 'funny, small and colourful';
}
if(country === 'Germany') {
weather = 'average';
food = 'wurst thing ever';
currency = 'funny, small and colourful';
}
var message = 'this is ' + country + ', the weather is ' +
weather + ', the food is ' + food + ' and the ' +
'currency is ' + currency;var language = {
name: 'JavaScript',
isSupportedByBrowsers: true,
createdIn: 1995,
author:{
firstName: 'Brendan',
lastName: 'Eich'
},
// Yes, objects can be nested!
getAuthorFullName: function(){
return this.author.firstName + " " + this.author.lastName;
}
// Yes, functions can be values too!
};var variable = language.name;
// variable now contains "JavaScript" string.
variable = language['name'];
// The lines above do the same thing. The difference is that the second one lets you use litteraly any string as a property name, but it's less readable.
variable = language.newProperty;
// variable is now undefined, because we have not assigned this property yet.language.newProperty = 'new value';
// Now the object has a new property. If the property already exists, its value will be replaced.
language['newProperty'] = 'changed value';
// Once again, you can access properties both ways. The first one (dot notation) is recomended.===!====!=if (country === "France") {
...
}var topper = (marks > 85) ? "YES" : "NO"; var object = {};
// Yes, simply a pair of curly braces! var object = new Object();for(condition; end condition; change){
// do it, do it now
}for(var i = 0; i < 10; i = i + 1){
// do this code ten-times
}if(x > 10 && x < 20) {
...
}if(country === 'England' || country === 'Germany') {
...
}toString is an Object.prototype's property, which was inherited. It has a value of a function, which returns a string representation of the object. If you want it to return a more meaningful representation, then you can override it. Simply add a new property to the adult object.var adult = {age: 26},
retrievedProperty = adult.age;
// The line abovevar stringRepresentation = adult.toString();
// the variable has value of '[object Object]'adult.toString = function(){
return "I'm "+this.age;
}var child = Object.create(adult);
/* This way of creating objects lets us easily replace the default Object.prototype with the one we want. In this case, the child's prototype is the adult object. */
child.age = 8;
/* Previously, child didn't have its own age property, and the interpreter had to look further to the child's prototype to find it.
Now, when we set the child's own age, the interpreter will not go further.
Note: adult's age is still 26. */
var stringRepresentation = child.toString();
// The value is "I'm 8".
/* Note: we have not overridden the child's toString property, thus the adult's method will be invoked. If adult did not have toString property, then Object.prototype's toString method would be invoked, and we would get "[object Object]" instead of "I'm 8" */ -1,7 +1,18 @@
describe('Feature: Adding a book', () => {
test('Example: User can add a book', async () => {
// Pour l'instant je me contente d'écrire le code le plus simple possible
+ class BookRepository {
+ lastSavedBook: { title: string } | undefined;
+ }
+
const bookRepository = new BookRepository();
- const addBook = new AddBookUseCase(bookRepository);
+
+ class AddBookUseCase {
+ async execute(book: { title: string }) {
+ bookRepository.lastSavedBook = book;
+ }
+ }
+
+ const addBook = new AddBookUseCase();
await addBook.execute({ title: 'Clean Code' });
var foo = 42;
var bar = 42;
var baz = "42";
var qux = "life";do{
// statement
}
while(expression) ;var i = 0;
do {
document.write(i + " ");
i++; // incrementing i by 1
} while (i < 10);

var bigStr = 'Hi ' + 'JS strings are nice ' + 'and ' + 'easy to add';// 1, 1, 2, 3, 5, and 8 are the elements in this array
var numbers = [1, 1, 2, 3, 5, 8];var umbrellaMandatory;
if(country === 'England'){
umbrellaMandatory = true;
} else {
umbrellaMandatory = false;
}if(country === 'England') {
...
} else if(country === 'France') {
...
} else if(country === 'Germany') {
...
}function double(x) {
return 2 * x;
}var double = function(x) {
return 2 * x;
};doThing(cars[0]);
doThing(cars[1]);
doThing(cars[2]);
doThing(cars[3]);
doThing(cars[4]);for (var i=0; i < cars.length; i++) {
doThing(cars[i]);
}// This is a comment, it will be ignored by the interpreter
var a = "this is a variable defined in a statement";/*
This is a multi-line comment,
it will be ignored by the interpreter
*/
var a = "this is a variable defined in a statement";Mark me as a comment
or I'll throw an error/*
Mark me as a comment
or I'll throw an error
*/assert(true);// Define two simple functions
var add_2 = function(x) {
return x + 2;
};
var double = function(x) {
return 2 * x;
};
// map is cool function that accepts 2 arguments:
// func the function to call
// list a array of values to call func on
var map = function(func, list) {
var output=[]; // output list
for(idx in list) {
output.push( func(list[idx]) );
}
return output;
}
// We use map to apply a function to an entire list
// of inputs to "map" them to a list of corresponding outputs
map(add_2, [5,6,7]) // => [7, 8, 9]
map(double, [5,6,7]) // => [10, 12, 14] // Imagine I had a pizza
var myPizza = {slices: 5};
// And I shared it with You
var yourPizza = myPizza;
// I eat another slice
myPizza.slices = myPizza.slices - 1;
var numberOfSlicesLeft = yourPizza.slices;
// Now We have 4 slices because myPizza and yourPizza
// reference to the same pizza object.
var a = {}, b = {}, c = {};
// a, b, and c each refer to a
// different empty object
a = b = c = {};
// a, b, and c all refer to
// the same empty objectprocess_add_2 = function(list) {
return map(add_2, list);
}
process_double = function(list) {
return map(double, list);
}
process_add_2([5,6,7]) // => [7, 8, 9]
process_double([5,6,7]) // => [10, 12, 14]// a function that generates a list processor that performs
var buildProcessor = function(func) {
var process_func = function(list) {
return map(func, list);
}
return process_func;
}
// calling buildProcessor returns a function which is called with a list input
// using buildProcessor we could generate the add_2 and double list processors as follows:
process_add_2 = buildProcessor(add_2);
process_double = buildProcessor(double);
process_add_2([5,6,7]) // => [7, 8, 9]
process_double([5,6,7]) // => [10, 12, 14]var buildMultiplier = function(x) {
return function(y) {
return x * y;
}
}
var double = buildMultiplier(2);
var triple = buildMultiplier(3);
double(3); // => 6
triple(3); // => 9var fruit = {
apple: 2,
orange:5,
pear:1
},
sentence = 'I have ',
quantity;
for (kind in fruit){
quantity = fruit[kind];
sentence += quantity+' '+kind+
(quantity===1?'':'s')+
', ';
}
// The following line removes the trailing coma.
sentence = sentence.substr(0,sentence.length-2)+'.';
// I have 2 apples, 5 oranges, 1 pear.var myCounter = {
number : 0,
plusPlus : function(){
this.number : this.number + 1;
},
isGreaterThanTen : function(){
return this.number > 10;
}
}3 + 5 = 83 + x = 8x = 8 - 3
-> x = 5x + y = 8x = 4
y = 4x = 3
y = 5var x = 5;
var y = 6;
var result = x + y;

var adult = {age:26},
child = Object.create(adult);
child.age = 8;
delete child.age;
/* Remove age property from child, revealing the age of the prototype, because then it is not overriden. */
var prototypeAge = child.age;
// 26, because child does not have its own age property.