Installing NodeJS on Fedora 26
Follow this tutorial to transfer the package to our local repository:Then install nodejs with dnf as follow: Printing Hello World
We can assign variables with var or let. For security issues: let do not use the variable beyond its scope as var does. The standard since 2015 is the use of let, so throughout this tutorial we are going to use let. We can assign numbers as well as strings, then differentiate the operator of comparison such as “==” and “===”, that check the content and the type.
Properties of an object can be also be code as well as its methods. In this case, we are going to define an object called student whose has a name, lastname, age and an action called say, to claim to his professor he did the homework.Creating Functions
There was a convention to use in ES5 the reserved word function to declare a function such suma in this case which sum two numbers a and b.In ES6, the standard for an simple arrow function defines the parameter of a function with = and the definition of the function is followed by the => structure.
Working with Loops
The use of loops is the similar as the way you use them in other programming languages as C or Python. In this case we are reusing the addOne function, previously declared to add a unit of a number. Initialize the counter i and then working with it while it is lower than 5. Whenever i is equal to 3, print the result of addOne on i.
Starting by declaring our array, arr defines a list of elements, no matter the type of each element. One way to print each element of arr is by using an index “i” that is assigned to 0 and loop until getting the length of the array (in this case from 0 to 2), to finally print each i position of arr. Another way is by defining a variable of the array. In this case fruit is part of the arr and when it is used inside a for loop, each word that is inside arr can be printed. key is used as index of the array, and printed:
There are two ways to declare a list of users. The first one is by declaring a list of users separated by commas and each user has its own attributes such as id and name. The other way is by assigning each user a,b, and c with its properties or attributes and then gathered together, in this case the list is called users.
To use forEach, there are another three ways to do so. Depending of the complexity of the code when you will have more lines of code, you can choose by 1) creating a function to getPeriod of the user then call it while the forEach is used. 2) Defining a function for user inside the forEach structure. 3) Use the => to apply an action on a specific object.
Filter and maps
We are defining item.id < 3 and it will filter the values of 0,1, and 2. Since we only have id 1 and 2, the length of SomeUsers is going to be 2. Map will work on each element of the array, so the length of each element of the array is going to be shown. Julita includes a blank: 7!
Callbacks or High order Functions are defining as parameter of another function based on the functional paradigm. In this introduction we have used them to call the elements and index of an array 🙂