Skip to main content
Filter by
Sorted by
Tagged with
-1 votes
3 answers
102 views

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 ...
No Tools No Craft's user avatar
0 votes
1 answer
45 views

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";...
Baba's user avatar
  • 13
-2 votes
2 answers
127 views

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 ...
emjKamara's user avatar
1 vote
0 answers
41 views

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 ...
alstorx's user avatar
  • 111
0 votes
1 answer
113 views

Here are two similiar codes except for the "use strict" part "use strict" { function a() { return 1; } } function a() { return 2; } ...
Alexandr's user avatar
0 votes
2 answers
157 views

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(...
713sean's user avatar
  • 385
2 votes
0 answers
53 views

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 ...
Rtyn's user avatar
  • 21
0 votes
4 answers
348 views

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, ...
matronator's user avatar
1 vote
0 answers
59 views

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 ...
mayur dayal's user avatar
0 votes
2 answers
221 views

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"); } ...
Arjuman Sreashtho's user avatar
0 votes
2 answers
66 views

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 ...
JSNinja's user avatar
  • 313
2 votes
1 answer
1k views

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'); ...
Drex's user avatar
  • 3,901
0 votes
1 answer
79 views

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 ...
spacing's user avatar
  • 800
1 vote
1 answer
62 views

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. ...
quizmaster987's user avatar
0 votes
1 answer
4k views

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 ...
Priyank's user avatar
  • 3,888
1 vote
1 answer
158 views

var functionVariable = function functionExpressionName() { functionExpressionName = 1; console.log(functionExpressionName) // function }; functionVariable(); If You run this example you can ...
Murad Sofiyev's user avatar
1 vote
1 answer
83 views

What are the differences between the following function declaration formats? When is it more correct to use which? From a beginner's perspective, and a high level (non-deep) point of view, they all ...
maze's user avatar
  • 959
0 votes
2 answers
88 views

There are many questions about recursion with function expressions. And there are two ways to do it: One is using named function expression and second is using arguments.callee. But at this time ...
mazza's user avatar
  • 59
1 vote
1 answer
53 views

This piece of code uniqueInteger.count = 0; function uniqueInteger() { return uniqueInteger.count++; } console.log(uniqueInteger()); console.log(uniqueInteger()); produces the following ...
DarkSun's user avatar
  • 449
1 vote
2 answers
458 views

Snippet 1: var a; // undefined variable named 'a' function a(foo) { // a function named 'a' var foo = "Hello World"; console.log(foo); } console.log(a); // output is: [Function: a], but ...
151SoBad's user avatar
  • 125
1 vote
2 answers
59 views

Given var stuffs = [ { id : 1, name : "orange"}, { id : 2, name : "apple"}, { id : 0, name:"grapes"} ]; var filterMethod1 = new function(o){return (o.id>=1);}; // this gives undefined ...
rustyengineer's user avatar
1 vote
1 answer
156 views

I have a question about this code below: function myfunc () { return 2 + 2; } console.log(myfunc); Does anyone know why, when we log 'myfunc' to the console, we get the entire function itself back? ...
Bail3y's user avatar
  • 51
0 votes
2 answers
40 views

In JavaScript we can declare a function and then assign to it, as follows: function spam() { return "spam 'n eggs"; } spam = spam(); spam(); // TypeError: spam is not a function. Does this code ...
JeremiahB's user avatar
  • 916
0 votes
3 answers
449 views

I have noticed something while playing around which has sparked a quick question. When code is executed in the global/window context, any function declarations get added as methods to the window ...
Brummy's user avatar
  • 193
-1 votes
1 answer
91 views

If (function foo(){}) is an expression due to the 'context' as "(Parenthesis)" are a grouping operator and grouping operator can only contain an expression. Which leads to the question, can you ...
Aleksei Maide's user avatar
1 vote
1 answer
175 views

The following code gave an error, on some version in firefox browser - linksHandle is not defined. The code is comprised of a function that at the bottom has a function named linksHandle. As far as I ...
user3021621's user avatar
13 votes
4 answers
11k views

I am learning javascript myself. I found if I declare a function with same arguments it just working fine: function func(a, b, a){ return b; } alert(func(1,2,3)); But if I do this : function func(...
Marymon's user avatar
  • 247
1 vote
0 answers
45 views

I tried calling function(v){alert(""+v);}(4); But warning came out function statement requires a name When I called using name function fname(v){alert(""+v);}(4); Nothing happenedBut when I called ...
Rahul Jain's user avatar
3 votes
1 answer
126 views

In JavaScript, when using a function expression (e.g. var myFunc = function() {...}), like any other variable declaration, you have to define the variable before using it. For example, the following ...
jbyrd's user avatar
  • 5,645
1 vote
1 answer
71 views

I will prefer to use function declaration all the time because I can place the function anywhere on the source file. If I use function expression, the function has to be placed at the top of the ...
guagay_wk's user avatar
  • 28.3k
1 vote
3 answers
253 views

A common method of creating private methods (of sorts) in JavaScript is this: Class = function (arg0, arg1) { var private_member = 0; var privateMethod = function () { return ...
Wingblade's user avatar
  • 10.1k
0 votes
1 answer
1k views

I have wrapped 95% of the 'parentCtrl' (Controller) within an 'IF' statement, this prevents any functions from triggering if the user isn't signed in and authorized. Since doing this I keep getting ...
user avatar
1 vote
1 answer
177 views

I'm refactoring legacy code. I can see that for functions used both declarations and expressions. I know that declarations are hoisted, expressions work as step-by-step execution. There are also named ...
Viacheslav Kondratiuk's user avatar
38 votes
2 answers
12k views

I'm trying to wrap my head around the new standardized block-level functions in ES6 by reading the raw spec. My superficial understanding was: Block-level functions declarations are allowed in ES6. ...
0rvidal's user avatar
  • 2,072
1 vote
2 answers
1k views

There's many javascript articles on the web comparing function declarations function foo (){} to function expressions var foo = function () {}. They usually mention things like hoisting, behaviour ...
Wingblade's user avatar
  • 10.1k
0 votes
2 answers
337 views

I recently search in the code of the library of knockout to find how observables are able to create dependencies with computed functions when we call it. In the source code, I found the function ...
Samuel's user avatar
  • 12.4k
4 votes
3 answers
1k views

Only functions expressions can be immediately invoked: (function () { var x = "Hello!!"; // I will invoke myself })(); But not function declarations? Is this because function declarations ...
amoeboar's user avatar
  • 355
1 vote
3 answers
3k views

While making several test projects for my small library of code I have come across many tutorials that go about making functions in many different ways. For example: Function Declarations ...
user3412869's user avatar
  • 1,425
5 votes
1 answer
1k views

I have just learned about the difference between Function Declarations and Function Expressions. This got me wondering about whether or not I'm doing things right in my AngularJS code. I'm following ...
mikesigs's user avatar
  • 11.5k
1 vote
1 answer
84 views

What is the difference between this: Library1 = function () {}; Library1.prototype.myFunc = function (p) { function helper1(p) {return p * 2; } function helper2(p) {return p * 4; } this....
user avatar
1 vote
1 answer
501 views

Why isn't this working using function declaration, but it's working perfectly using function expression? Assuming that the only difference is how the browser loads them into the execution context. ...
Pompeyo's user avatar
  • 1,469
0 votes
1 answer
146 views

I want to use the property of "caller" for a function which is defined here It works fine for this style of function declaration function g() { alert(g.caller.name) // f } function f() ...
arvind's user avatar
  • 127
2 votes
2 answers
74 views

I'm reading the portion of ECMA 262 v5 script that speaks of Function definitions. For both function declarations and function expressions, the following is mentioned: Return the result of creating ...
contactmatt's user avatar
  • 18.8k
6 votes
1 answer
238 views

I just ran into a problem when defining a function in a block scope. Consider the following program: try { greet(); function greet() { alert("Merry Christmas!"); } } catch (error)...
Aadit M Shah's user avatar
  • 74.5k
4 votes
3 answers
247 views

I saw this on Twitter and I couldn't explain it either. Defining a onload function in the following two manner works: onload = function(){ console.log('this works'); }; window.onload =...
Ashfame's user avatar
  • 1,769
0 votes
2 answers
265 views

I'm using the following function named isExpression to determine whether some JavaScript code is an expression: function isExpression(code) { try { new Function("return " + code); ...
Aadit M Shah's user avatar
  • 74.5k
3 votes
2 answers
4k views

How do browsers handle multiple function declarations with the same name? Specific test case is below - NOTE: I know this does not make sense to allow a server script to create more than one function ...
user1226337's user avatar
80 votes
7 answers
39k views

I notice that in CoffeeScript, if I define a function using: a = (c) -> c=1 I can only get the function expression: var a; a = function(c) { return c = 1; }; But, personally I often use ...
Grace Huang's user avatar
  • 5,757
90 votes
4 answers
21k views

Why does the first one of these examples not work, but all the other ones do? // 1 - does not work (function() { setTimeout(someFunction1, 10); var someFunction1 = function() { alert('here1'); }; })()...
james's user avatar
  • 13.4k
2 votes
1 answer
350 views

I see that in the answer of In Javascript, why write "var QueryStringToHash = function QueryStringToHash (query) { ... }"? which is doing something like var foo = function foo(param) { ...
nonopolarity's user avatar