52 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
-1
votes
3
answers
109
views
Cypress Error: 'cy.within() can only be called on a single element'
I've received a Cypress error suggesting that multiple elements contain the searched value, so it cannot recognize the requested one.
Here is the Cypress script I've used for testing:
it('Check all ...
0
votes
1
answer
46
views
Why order of sloppy-mode function statement in block affects global variable differently?
snippet 1 -> output is "b"
if (true) {
x = "b";
function x() {}
}
console.log(x); //b
snippet 2 -> output is ƒ x() {}
if (true) {
function x() {}
x = "b";...
-2
votes
2
answers
137
views
Can some please explain to me the difference between the function keyword and const in declaring a function [duplicate]
As demonstrated in the below examples, I used the function keyword to declare a function that will generate a random integer number within a range, and I also used a const keyword to declare another ...
1
vote
0
answers
43
views
JavaScript Immediately Invoked Function - Distinguishing Between JavaScript Function Expressions and Declarations [duplicate]
In my journey of learning JavaScript, I encountered my first practical use case for an Immediately Invoked Function Expression (IIFE).
However, I'm struggling to understand the distinction between a ...
0
votes
1
answer
117
views
Does hoisting of functions behave differently when strict mode is off? [duplicate]
Here are two similiar codes except for the "use strict" part
"use strict"
{ function a() {
return 1;
}
}
function a() {
return 2;
}
...
0
votes
2
answers
161
views
Javascript Hoisting - How are we Accessing Certain Variables?
I have two questions about hoisting:
The way function declarations are hoisted is that they go to the very top, even above variable declarations, to my understanding.
If we have this code:
function fn(...
2
votes
0
answers
58
views
collapsing function and variables name [duplicate]
Here is the fact in Head first js,
when the browser evaluates a function declaration, it creates a function as well as a variable with the same name as the function, and stores the function reference ...
0
votes
4
answers
349
views
Function works only in Safari, other browsers throw `Uncaught TypeError: X is not a function`. Where's the problem?
I implemented a new feature to our CRM and everything works as it should on Safari (macOS), but it throws Uncaught TypeError: X is not a function on every other browser we tested it on (Chrome, ...
1
vote
0
answers
59
views
Invoking function declaration in JavaScript [duplicate]
I have a doubt regarding how the function declaration are invoked in JavaScript.
I have read somewhere that function declaration can be accessed anywhere within the function it was declared on.
Lets ...
0
votes
2
answers
227
views
JavaScript hoisting for function expression and function declaration [duplicate]
I am learning hoisting in JavaScript and practicing some examples.
In an example I am confused of it's output.
Here is the example code:
var f = function(){
console.log("Expression");
}
...
0
votes
2
answers
66
views
Are these 2 JavaScript statements equivalent? [duplicate]
These 2 statements seem to do the same thing.
const handleClick = () => alert('foo');
and
function handleClick() {
alert('foo');
}
Are they identical and just syntactically different? The ...
2
votes
1
answer
1k
views
Why arrow function has to be declared above the caller function
In a javascript file, when I declare a function using function keyword, I can placed my function after my caller function, something like
// test.js
function myCaller() {
foo('hello world'); ...
0
votes
1
answer
81
views
toggling variable inside Module Pattern using function declaration vs function expression
I have a module pattern with a variable setting the currentPlayer to 1. I use a function expression to toggle that variable
const game = (() => {
let currentPlayer = 1;
const ...
1
vote
1
answer
62
views
Is an anonymous function as a parameter a function declaration or a function expression?
Assuming a function declaration is a statement where the function keyword is the first word of the statement, e.g.:
function() { console.log("foo") };
Assuming that a function expression is e.g. ...
0
votes
1
answer
4k
views
Why do function declarations get hoisted and function expressions don't?
According to hoisting definition:
Hoisting is a JavaScript mechanism where variables and function
declarations are moved to the top of their scope before code execution
Why do function ...