1: Example:
const square = function (x){
return x * x;
};
2: let is local, while var is global
3: A pure function does not have any side effects, nor relies on those from other code, to produce value.
1: Example:
const square = function (x){
return x * x;
};
2: let is local, while var is global
3: A pure function does not have any side effects, nor relies on those from other code, to produce value.
How can you create a function in Javascript?
A function is created with an expression that starts with the keyword function.
What is the difference between var and let in regards to scope?
The difference between them is that var is function scoped and let is block scoped.
The var variable can be used gobally and let is limited to the block.
What is a pure function?
A function is called pure function if it always returns the same result for same argument values and it has no side effects like modifying an argument.
How can you create a function in JavaScript
Function name(parameter1, parameter2, parameter3) {code to be executed}
A function is a set of parameters, containing statements to be executed.
What is the difference between var and let in regards to scope?
var: visible throughout the whole function/global scope if not in a function
let: Local to the block declared in
What is a pure function?
Does not create side effects or rely on side effects
You define a function much like defining a variable:
function test(){ function code};
The difference is that var creates a variable that can be referenced within the global scope, let creates a variable that can only be referenced in the immediate enclosing block.
A pure function always gives the same output, providing the same input is provided. It also does not produce any side effects.
How can you create a function in Javascript?
By creating a expression using the word function.
What is the difference between var and let in regards to scope?
Let is local to the block it is declared in. If located inside of a loop it cannot be seen by the code before or after it. Var keyword defines a variable globally regardles of the block scope
What is a pure function?
A pure function always returns the same result given the same parameters.
1.) A Function can be created like this:
function square(x) {
return x * x;
}
Square is the name of the function; x is the name of itâs only arguments; and return x * x is the body of the function.
2). let in the case of declaring a variable is very limited in scope to the block, expression or statement that it is being used in.
var is a keyword that defined a variable globally, or locally to an entire function regardless of the block.
3). Purity is talking about whether or not a function will have side effects.
1- By using the keyword âfunctionâ and parentheses that comes after it and the arguments can be placed in it or it has no arguments. Then the statement is to be placed between the brackets {}.
2- If you define a variable in a block with keyword âletâ, it canât be seen out of this block. It is local to this block. But if you define the variable by keyword âvarâ, it canât be seen by the whole code(global) if it was not in a function.
3- 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 -
Use the keyword function followed by the name of the function.
After the function name, open and close parentheses.
After parenthesis, open and close curly braces.
Within curly braces, write your lines of code.
2 - The main difference is scoping rules. Variables declared by âvarâ keyword are scoped to the immediate function body, while âletâ variables are scoped to the immediate enclosing block denoted by { }
3 - Pure Function is a function that does not depend on any state, or data change during a programâs execution rather it only depends on its input arguments and always returns the same result if the same arguments are passed
1:
With an expression that starts with the keyword âfunctionâ.
Example:
const sum = function(x, y) {
return x + y;
}
sum(4,9)
// 13
2:
When let and const are declared they are local to the block they were declared in.
For example, putting them in a loop will cause them to not be visible to the code
before or after said loop.
When var is used to declare a binding it can be used by code outside of that local block
and often it is globally available.
3:
Itâs a value-producing function that doesnât have any side effects and doesnât rely on side effects from other code.
It always produces the same value.
A function is created with the keyword âfunctionâ and a paramater that defines the action to be executed when the function is invoked.
let is local, as in applicable only to the block it is declared in and var is a global fuction that applies to the entie fuction regrdless of the block.
A pure fuction is a fuction that gives a constant non vaiable output if given the same input. It produces not additional side effects.