Excellent answer sir! really well documented! keep it like that please!
Carlos Z.
Excellent answer sir! really well documented! keep it like that please!
Carlos Z.
eg.
function welcomeMessage () {
alert(âwelcome everyoneâ);
}
Var is used for the global environment and let is used for the block scope of a function
A pure function is a function that always returns the same value when the same input is given and produces no side effects
The concept is very abstract for me so far, good thing is that Iâm learning as I go. I think I understood.
Thanks for you review.
Hi @Jody,
Nice answers
Just a comment about Q2âŠ
In fact, variables declared with let
are also available globally if they are declared outside of all code blocks and functions.
Take a look at this post for some clarification. And if you would like to go a bit deeper, then try this post.
Hey @kmilo_Mart!
Donât worry, the differences between var
and let
are difficult to grasp at firstâŠ
âŠtake a look at this post for some further clarification. And if you would like to go a bit deeper, then try this post.
How can you create a function in Javascript?
You assign the function to a variable(with parameters) and {execute the instructions within the curly braces}
const function = function(parameters){instructions to be executed}
What is the difference between var and let in regards to scope?
Bindings declared with let are in fact local to the block that they
are declared in, so if you create one of those inside of a loop, the code before and
after the loop cannot âseeâ it. bindings, created with the var keyword, are visible
throughout the whole function that they appear inâor throughout the global
scope, if they are not in a 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
var x = function(i) {return i*i};
function x (i) {return i*i};
var x = i => i*i;
var is global, let is local
â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âfor example, it doesnât read global bindings whose value might change. A pure function has the pleasant property that, when called with the same arguments, it always produces the same value (and doesnât do anything else).â
How can you create a function in Javascript?
a. with the function keyword: function function_name(arguments*) { func_bodyâŠ}
b. const function_name = function(arguments) {func_body};
c. arrow function: const function_name = (arguments) => { function_body};
What is the difference between var and let in regards to scope?
let declares bindings to be local to the block; while var bindings are global scope, or visible throughout the whole function that they appear in.
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.
How can you create a function in Javascript?
Functions are created using a keyword and then setting parameters to the function,
= function().
What is the difference between var and let in regards to scope?
The binding let limits the scope of the function to the block.
What is a pure function?
A pure function is a specific function that produces value. It creates no side effects and uses no side effects created by other code. It reads no value that may be subject to change.
Bind something to an expression with a set of parameters & call it with the command âfunctionâ
As far as scope var = is a global binding while let = is expression specific
A pure function is one that has none & relies not on âside effectsâ. You call it. It functions regardless of environmental influences.Inout values rule the day!(respectively)
Hi @FrankB,
Youâve missed out the arrow in your arrow function example:
const functionName = (var_1, ..., var_n) => {...}
Hi @CeesQ,
They can be, but they can each have other types of scope as well, so that isnât the difference. The differences between var
and let
are difficult to grasp at firstâŠ
âŠtake a look at this post for some clarification. And if you would like to go a bit deeper, then try this post.
Hi @DeezSats,
- How can you create a function in Javascript?
Functions are created using a keyword and then setting parameters to the function,
= function().
You are part of the way there, but youâve omitted some important details, such as the function name, and the function body enclosed in curly brackets.
- What is the difference between var and let in regards to scope?
The binding let limits the scope of the function to the block.
You seem to be confused here⊠let
isnât a binding; its a keyword declaring a binding. It defines the scope of the binding, not a function
⊠and how is let
different to var
?
The differences between them are difficult to grasp at first, but take a look at this post for some clarification. And if you would like to go a bit deeper, then try this post.
Hi @AliasFresh,
- How can you create a function in Javascript?
Bind something to an expression with a set of parameters & call it with the command âfunctionâ
⊠your description is confusing, to be honest. You can bind the function to a variable, yes; but either way you normally need to use the keyword function
, give the function a name, and, as youâve said, a set of optional parameters enclosed within parentheses. You then also have the function body enclosed in curly brackets, which contains the block of code that will be executed when the function is called. You donât call the function with the keyword function
(this keyword defines (or declares) the function. You call a function by appending parentheses to its name and placing the arguments (which become the parameters) within the parentheses.
I hope thatâs now clearer.
- What is the difference between var and let in regards to scope?
As far as scope var = is a global binding while let = is expression specific
A binding declared with var
can have global scope, but not always. And let
isnât expression specific, but specific to the code block it is declared in.
The differences between var
and let
are difficult to grasp at first, but take a look at this post for some further clarification. And if you would like to go a bit deeper, then try this post.
Hi @Cryptojunkie,
Q1 & 3
- What is the difference between var and let in regards to scope?
- Var is for global bindings and let is used for local bindings
They can be, but they can each have other types of scope as well, so that isnât the difference. The differences between var
and let
are difficult to grasp at first, but take a look at this post for some clarification. And if you would like to go a bit deeper, then try this post.
Oh my⊠I meant to say let limits the scope of the binding to the block.
geez what I wrote doesnât even match my notes.
Iâll check out the post to be sure I have it proper.
Ok those posts helped for better understanding.