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
Related
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
This question already has answers here:
Does a browser truly read JavaScript line by line OR does it make multiple passes?
(6 answers)
How JavaScript interpreter interpret code?
(3 answers)
How does an interpreter run code?
(1 answer)
How does an interpreter interpret the code?
(4 answers)
Why does Java code need to be compiled but JavaScript code does not
(4 answers)
Closed 2 years ago.
It is true, that javascript works like this:
Does the interpreter pass 1 time throughout the code?
and the second time it executes the code?
If this is true, where can I find information that characterizes my question?
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);
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
This question already has answers here:
How do you find out the caller function in JavaScript?
(36 answers)
Closed 9 years ago.
I have a common error function which is called from many places. I want to know from which function this was called. Is there any way to do it?
In any javascript function you can use
arguments.callee.caller
if You want to execute JS in chrome you have to do like this
go to console and type your JS and enter!