Hi @Matoshi,
Great explanation of the different ways to create a function!
Q1 and 3
In terms of Q2, take a look at this post for some clarification. And if you would like to go even deeper, then try this post.
Hi @Matoshi,
Great explanation of the different ways to create a function!
Q1 and 3
In terms of Q2, take a look at this post for some clarification. And if you would like to go even deeper, then try this post.
1 - By creating an expression beginning with function() assigning parameters(if any), and a body with something to execute.
2 - let = declares a variable limited to the block, expression, or statement.
var = sets a variable globally
3 - A pure function is a value producing function without side effects from other code. When called with the same arguments it always generate the same results.
Great job with explaining Q2. No One, but you make it clear for my, finally Cheers
1.How can you create a function in JavaScript?
A function is created by expression that starts with the keyword function, followed by a name followed by parameters. The function name can contain letters, digits, underscore, and dollar signs (same as variables.)
Function name(parameters1, parameters2){
//Code to be executed
}
2.What is the difference between var and let in regards to scope?
let variable inside block of code is LOCAL and canât be defined outside the scope, var variable inside a scope is GLOBAL and can be defined outside the scope letâs see my example:
let IamGlobal = âsomeValueâ
If(true){
var iamLocal = âsomeMorevalueâ
Console.log(âIamglobalâ)
Console.log(âiamLocalâ)
}
Console.log(âiamLocalâ)
Console.log(âiamGlobalâ)
Output:
someValue
someMoreValue
someMoreValue
someValue
3.What is a pure function?
Itâs always has to return the same value for the same inputs also pure function has no side-effects.
Hi @Junte!
Q1 and 3
limited to the block â Yes
limited to the expression or statement â No
In terms of Q2, take a look at this post for some clarification. And if you would like to go a bit deeper, then try this post.
Thanks for the feedback and the reading material Jon
How can you create a function in Javascript?
By defining its parameters and the caller.
What is the difference between var and let in regards to scope? Binding declared with let is valid only in the block where is declared, but a binding declared with var is visible on the whole function
What is a pure function? A pure function is a specific kind of value-producing function that not only has no side effects but also doesnât rely on side effects from other code. A pure function when called with the same arguments, it always produces the same value (and doesnât do anything else).
Hi @cincinnato,
Q3
There is more to creating a function than this⌠can you provide more detail?
In terms of Q2, take a look at this post for some clarification. And if you would like to go even deeper, then try this post.
Hi again @sherlock!
Q1 and 3
In terms of Q2, take a look at this post for some clarification. And if you would like to go even deeper, then try this post.
function functionName(parameter1,parameter2){ return(
parameter1 + parameter2);
};
//then invoke the function by defining the parameters
console.log(functionName(1, 2));
// result is 3
What is the difference between var and let in regards to scope?
var defined bindings are globally recognized while let defined bindings are only locally recognized within the same block in which it was defined.
What is a pure function?
A pure function produces no side effects and the same parameter input will always give the same output. It is independent of any other code outside of itself can be easily moved around within a program.
Excellent answer sir! really well documented! keep it like that please!
Carlos Z.
A function is created with an expression that starts with the keyword function. Functions may or may not have a set of parameters.
var defines a variable globally while let refers it locally
A pure function is a function that given the same input will always return the same output and it producess no side effects.
f(x) = functionName(parameters) {code to execute}
Var scopes are visible in the entire function (global binding), and can be called from outside the function, while let scopes are only visible in local bindings.
A pure function always produces the same value and it doesnât read global bindings that may change value. It can only be substituted by its return value. It doesnât have side effects and doesnât rely from other functionsâ side effects.
7 Functions
1 How can you create a function in Javascript?
When you use the keyword âfunctionâ within an expression, you can create a function value. You can also create a function used as an statement that will declare a binding.
2 What is the difference between var and let in regards to scope?
Let declared in a scope stays local and is not visible in a global scope. Var is different. It ends up in the nearest scope or in the global scope.
3 What is a pure function?
A pure function is a specific kind of value-producing function that not only has no side effects but also doesnât rely on side effects from other code.
1. How can you create a function in Javascript?
A function is created with an expression that starts with the keyword âfunctionâ.
2. What is the difference between var and let in regards to scope?
Bindings declared with âletâ and âconstâ are local to the block, expression or statement that they are declared in, while bindings declared with âvarâ are visible throughout the whole function that they appear inâor throughout the global scope if they are not in a function.
3. What is a pure function?
A pure function is a value-producing function that when is called with the same arguments it always generate the same outputs. A pure function has no side effects and doesnât rely on side effects from other code.