Questions tagged [function-expression]

100 questions
0
votes
2 answers

Function Expression Parameter is not assigned a value, but has a value

I'm hoping someone can explain how the the below function expression works. The parameter 'p' has not been assigned a value, however it is used in the body of the function for calculations (defining the "angle" and "tail" variables) and as an…
0
votes
2 answers

Passing parameter to method in array.map

How can i pass parameter to a method which is passed as parameter inside an array. map method. var result = [1,2,3]; var updatedResult = result.map(modifierMethod); function modifierMethod(cellValue){ return cellValue* dynamicValue} I want to pass…
starhunter
  • 165
  • 10
0
votes
0 answers

javascript function expression vs declaration

How is that possible that code below doesn't alert undefined? From my understanding only variables names declaration were hoisted and then on createWorkout() call it's should be undefined but it's not and works perfectly fine. var start = function()…
0
votes
1 answer

Function returns undefined in Javascript

Can not figure it out how to return value (string) from this function: function loadPage(url) { var xhttp = new XMLHttpRequest(); xhttp.open("GET", url, true); xhttp.send(); xhttp.onreadystatechange = function() { if…
0
votes
1 answer

Sinon spy on function expression

is it possible to make sinon spy on function expressions? Look this code for example. function one() { return 1; } function two() { return 2; } function three() { return 3; } function myMethod() { var n1 = one(); var n2 = two(); var…
Alejandro Nanez
  • 335
  • 2
  • 6
  • 16
0
votes
3 answers

lexical scopes for function expressions

If we divide the operation of javascript engine into compilation phase (where that whole lexical scope diagram is setup) Vs running phase (where code is executed using lexical scope setup in compilation phase), when is the scope for function…
noi.m
  • 3,070
  • 5
  • 34
  • 57
0
votes
1 answer

Default Parameters in Function Expressions

Default parameters in javscript function declerations can be achieved with a simple assignment as follows: function foo(arg1 = 'default1', arg2 = 'default2') { ... } But how can I have default parameters for function expressions, as the following…
Grateful
  • 9,685
  • 10
  • 45
  • 77
0
votes
2 answers

Declaring functions in JS: Named and Unamed expression

Recentley I began looking into the JS library Typeahead as a solution to a predictive search box. However upon looking at the code to implement it I began to look into things a little deeper and it led me to declaring functions in javascript. I…
Javacadabra
  • 5,578
  • 15
  • 84
  • 152
0
votes
1 answer

Error/Warning in Javascript: Function inside loop

I'm new to JavaScript, and am learning it from an online tutorial. The current expression is about the use of function expressions, and specifically - returning a function expression from inside a function. Here's the code: //array of all…
Manish Giri
  • 3,562
  • 8
  • 45
  • 81
0
votes
2 answers

javascript function expression within function

The working javascript snippet below does not include validation as it is only being used for learning purposes. However, I am not understanding the flow of events after variable 'isBetween' is defined within the buildBoundDetector() function. Why…
user1645914
  • 371
  • 6
  • 23
0
votes
3 answers

why does the named javascript function persist?

This is an adaptation of what you'd find in john resig's Learning Advanced Javascript app. var math = { fact: function fact(n){ return n > 0 ? n * fact(n-1): 1; }, fact1: function (n) { return n > 0? n * math.fact1(n-1) :…
deostroll
  • 11,661
  • 21
  • 90
  • 161
0
votes
1 answer

Conventions for "function expression" declaration

Im new to js and its sometimes hard for me to get used to its code conventions. So i have a question, how i should declare function expression? Look at my code, is it right how i did it, or there are better practices? function onAddButtonClick() { …
Azaro
  • 35
  • 1
  • 1
  • 9
0
votes
2 answers

Updating values with a function, returning not working

So I am using a function to update my values, but I can't then get them back. I see values don't get updated, but is there any way of saving them as a reference to the return of the function. function Amphibia(wheelRadius, finsPerPropeller,…
Boyan Hristov
  • 1,067
  • 3
  • 15
  • 41
0
votes
1 answer

javascript returning functional expressions vs declaring variables within a function

Take the following function: function createGlobalVar() { y = "foo"; } y //"foo" in the absence of the keyword 'var', which would make y a local variable, the function climbs up the scope chain to try and find where y exists. Without any…
0
votes
0 answers

Why function definition in this excerpt is interpreted as function expression

I was learning about JavaScript Immediately Invoking Function Expression (IIFE) from here. In this Ben very well explains why directly invoking function doesn't work: function(){ /* code */ }(); // SyntaxError: Unexpected token ( …
Mahesha999
  • 22,693
  • 29
  • 116
  • 189