JavaScript Study Notes
Minhas notas de estudo sobre JavaScript até o momento
My learning notes about JavaScript
Tip1: use this jsbin.com for praticing JavaScript.
let & const
Var is simply the way we create variables in JavaScript;
Boths, let and const, are two diferents types of variables introduced at ES6. See detais about them below.
- Let : used for variable values 'values that might change as needed'
- Const: as the name says, it's a variables used for constant values 'never gets a new value'
Some examples
//Let example
//Something that might change
let userName = "Victor";
console.log(userName);
userName = "Victor Luan";
console.log(userName);
// Const example
// Something that never changes
const victorsGirlfriend = "Catalina"
console.log(victorsGirlfriend);
victorsGirlfriend = "Another girl"
console.log(victorsGirlfriend);
Console log
"Victor"
"Victor Luan"
"Catalina"
Arrow Funcionts
//Commoly functions are like:
funciont myFunc(){
...
}
//Arrow functions are like these:
const MyFunc = () => {
....
}
//Here a function is being set into the constant.
It will help to no more issues with this keyword.
"When you use this inside an arrow function it will always keep its context and not change it surprisingly on runtime."_
Some examples
// Arrow Function Example
//One way of syntax
const example = (e) => {
console.log(e)
}
//or
const printMyName = name => {
console.log(name)
}
printMyName("Victor")
// if the function has no parameters, so
const printNickName = () => {
console.log("Vex")
}
printNickName()
// For more the one parameters has to go on parentheses
const nameAndAge = (name, age) => {
console.log(name, age)
}
nameAndAge("Victor", 28)
// Function body outside of the arrow
// So we can have the bellow function like this
const mutiplyExample = (number) =>{
return number * 2;
}
// as so it can be writen like this
const mutiply = number => number * 2;
console.log(mutiply(2))
Console log
"Victor"
"Vex"
"Victor Silva"
28
4