Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
There's youtube video explaining something about JS (3 hours long)
https://youtube.com/watch/... -
About let vs var:
// var
for (var i = 0; i < 10; i++);
console.log(i); // will print last assignment of I
// let
for (let i = 0; i < 10; i++);
console.log(i); // error -
{
let i = 1;
console.log(i); // 1
// new scope
{
let i = 2;
console.log(i); // 2
}
console.log(i); // 1
} -
{
var i = 1;
console.log(i); // 1
{
var i = 2; // will replace I that was declared before
console.log(i); // 2
}
console.log(i); // 2
} -
The () => {
//stuff
}
is just a shorthand to create functions. That is very useful for callbacks, now you can simply write
someFunction(() => {
//callback
});
instead of
someFunction(function() {
//callback
}}); -
Function:
function Obj () { console.log(this); }
new Obj(); // his "this" points to himself.
Arrow function:
// creates anonymous function, you can't give him a name with arrow statement
var Obj = () => { console.log(this); }
new Obj(); // error, Obj is not a constructor
Obj(); // this points to Window or outer scope. -
@Pogromist that 'var'-example: Javascript does THAT? Literally every other language does proper variable scoping. Like, what the hell?
-
@PrivateGER Oops, I didn't mean to make a joke. I see that I missed a word... Is the joke that JS programs crash and burn every time you make a typo?
Currently re-learning JS because I stopped JS for a while. ES6, wtf? Can someone explain the difference between the different ways of creating functions, and the difference between let and var. please? (Especially the function thing that’s got be fucked up)
question
javascript