Problem with simple variable assignment in Javascript [duplicate] - javascript

This question already has answers here:
Are 'Arrow Functions' and 'Functions' equivalent / interchangeable?
(4 answers)
`this` is undefined in Dev Tools when using arrow function
(2 answers)
Closed 4 years ago.
Facing a Javascript problem that has to be simple. Going nuts.
I declare and assign a variable as usual: 'let that = this';
When running the code in the Chrome debugger, 'this' is defined and has a value, but 'that' remains undefined. I know that 'this' is fickle in Javascript, but we're speaking the line after the assignment.
Any idea of what would happen? This is in a quite simple event handler, don't see where there could be a trap.
I started using Flow and transpiling JS with Codekit. I have the impression that Chrome debugger has gone a bit unstable since, could it be related?
Many thanks!
Screenshot in Chrome debugger

Related

What does Object.constructor.constructor('alert(1)')() actually do in javascript? [duplicate]

This question already has answers here:
What's going on in this piece of Javascript?
(1 answer)
What is instance.constructor.constructor and how does it work?
(1 answer)
How is this function created? A = (0)['constructor']['constructor']
(1 answer)
Obfuscated Javascript in an exploit kit using Array's constructor
(2 answers)
Clever JavaScript to bypass eval method [duplicate]
(1 answer)
Closed 1 year ago.
I am involved in Application security and often times I've used
{{constructor.constructor('alert(1)')()}}
blindly in AngularJS applications to escape the sandbox in older versions. Recently I've been trying to understand what this really means and how it works. I tried reading about object constructors and understand that an object constructor points to the object type. so for example.
var a = new String;
console.log(a.constructor);
will print out String and if I do a.constructor.constructor this will print out {}
Now my question is how does object.constructor.constructor('ANY FUNCTION HERE')() lead to that function being executed in javascript

Explain Closures in modern javascript [duplicate]

This question already has answers here:
How do JavaScript closures work?
(86 answers)
Closed 2 years ago.
I have been learning javaScript lately but I got confused in understanding the concept of closures.How does JavaScript closures actually work ?
A  closure gives you access to an outer function’s scope from an inner function
for more info you can follow this link-
http://sleeplessgeek.blogspot.com/2009/12/so-what-are-these-closure-thingys.html

How to add a pause in JavaScript? [duplicate]

This question already has answers here:
What is the JavaScript version of sleep()?
(91 answers)
Closed 2 years ago.
I've looked everywhere and can't find a solution. I'm using the console part of developer tools on chrome if that helps :)
I've tried various configurations such as the example below, and all give me an error
setTimeout(s)5
I'm not sure exactly what you are trying to do, but I think you need to pass a function and the length of timeout into the setTimeout method like this example
setTimeout(function(){ alert("Hello"); }, 3000);

Is function(){}() valid? [duplicate]

This question already has answers here:
Location of parenthesis for auto-executing anonymous JavaScript functions?
(4 answers)
Closed 5 years ago.
In a Javascript programming community, someone asked "How to declare anonymous method and run it immediately?" then others answered (function(){})() and (function(){}()).
People who answered (function(){}()) says that is correct and it's possible to run, but ideone says that is wrong and I think that is incorrect.
Following links are for comparison between SpiderMonkey and Rhino.
http://ideone.com/rKaYtW
http://ideone.com/Lblb7w
Is (function(){}()) really correct on Javascript?
"but ideone says that is wrong"
If you are talking about the error in the links you show, that's because you didn't separate the two examples with a semicolon, so the second one is having its outer set of parentheses interpreted as a function call of the previous expression.
(function(){
print("This is what I want.")
})() // <<< no semicolon causes the error here
(function(){
print("This may be what I want.")
}())

Javascript function compiling? [duplicate]

This question already has answers here:
Why can I use a function before it's defined in JavaScript?
(7 answers)
Closed 10 years ago.
I have noticed that when coding in javascript, it doesn't matter if i declare the function before or after i call it. In other languages it will cause an exception, but when running javascript in chrome it works just fine. Is that only in chrome, or is that normal?
What you're seeing is function hoisting in action: http://elegantcode.com/2011/03/24/basic-javascript-part-12-function-hoisting

Categories

Resources