Functions - Reading Assignment

  1. How can you create a function in Javascript?
    A definition of a function starts with the keyword function, followed by the name of the function. After the name of the function the parameters are given in parantheses separated by comma. The number of parameters can range from zero to arbitrarily many parameters. In usual cases you will have a small fixed number of parameters when you define a function. The body of a function contains the code to be executed and it is placed inside curly brackets.

  2. What is the difference between var and let in regards to scope?
    A binding declared with let is local to the block that it is declared in, while a binding declared with var is 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 specific only produces a value and has neither side effects nor it relies on side effects from other code. A pure function has the property that it always produces the same value, when called with the same arguments.

2 Likes
  1. A function is created with an expression that starts with the keyword “function”.
  2. “let” is only available inside the scope of block while “var” can be accessed locally and globally.
  3. The function always returns the same result if the same arguments are passed in.
1 Like

How can you create a function in Javascript?

  • You can create a function with an expression that starts with the keyword function and the having some set of parameters that will be used within the function. Within the body of the function you will create a statement that will run when the function is called.

What is the difference between var and let in regards to scope?

  • let is only visible within the function that it is created in and var can be called from outside the function.

What is a pure function?

  • A pure function is a function that does not create any side effects or rely on side effects
1 Like

Use a “function” declaration. The “function” keyword goes first, then goes the name of the “function”, then a list of parameters between the parentheses, and finally the code of the “function”, also named “the function body".
2.
“let” can be only available inside the scope like in “for” loop, and “var” can be accessed outside the loop “for”
3.
Its a specific kind of value-producing function, that has no side effects and doesn’t depending on side effects from other code.

1 Like

1. How can you create a function in JavaScript?

To create a function, from my understanding, is to use the function keyword. This can be used as a declaration or expression of a function. for example:

function myNote(a, b) {

return a * b;

}

2. What is the difference between var and let in regards to scope?

The difference is that var is a function scope and let is a block scope which means var carries throughout the program.

3. What is a pure function?

A pure function does not read global binding and does not has side effects, but it does produce value.

1 Like

1- A function is created with an expression that starts with keyword function. Functions have a set of parameters and a body which contains the statements that are to be executed when the function is called.

2- In regards to scope, let declares a variable limited to the block, statement, or expression on which it is used. Var, on the other hand defines a variable globally, or locally to an entire function regardless of block.

3- They have no side effects and do not rely on side effects from other code.

1 Like

How can you create a function in Javascript?

You need the expression “function”, parameters in which the function will act and a body of statements that are meant to be executed when the function is called to act.

What is the difference between var and let in regards to scope?

The “let” loop is local and con only read information inside the function that it’s a part of.

The “var” loop is global and will read information in the entire function, or the entire program if it’s not in a function.

What is a pure function?

A pure function is a function that has no side-effects neither does rely on side-effects of other code. It should work regardless of context

1 Like
  • How can you create a function in Javascript?

We can create functions in JavaScript in several different ways. However in general we must create a binding of a ‘keyword’ to an expression with specific parameters and statements.

  • What is the difference between var and let in regards to scope?

a ‘var’ and ‘let’ differ within the scope that they are used. With ‘var’ the scope of the variable that we are creating will be globally, meaning that its definition will be applied throughout the whole environment. While ‘let’ will have a scope that is much more local within the block that we may be only using in the immediate moment.

  • What is a pure function?

A pure function is very important for our environment because like ‘hashing’, when given the same input, a pure function will always give us the same output. Also there can be no side effects as it would effect external states. A pure function cannot rely on the time of day, random numbers within the code or anything that depends on IO.

1 Like

with the function() keyword.

var is global and let is locally scoped.

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

1 Like
  1. How can you create a function in Javascript?
    Functions are created when an expression starts with the keyword function. Functions have a set of parameters and a body, which contains statements to be executed when the function is called.

  2. What is the difference between var and let in regards to scope?
    Bindings declared with let are local to the block they are declared in, if it is created inside a loop, the code before and after the loop cannot "see"it. Using var is visible throughout the whole function they appear in or global scope, if they are not in a function.

  3. What is a pure function?
    Pure functions are value-producing functions that has no side effects, but also doesn’t rely on side effects from other code.

1 Like
  1. There are 3 main ways to write functions in JS. First is the regular one, when the binding name is in front, followed by teh keyboard, the parametes within parameters and at the end the bpdy between {}. EX: const square = function (x) { return x * x; }. The second option is the Declaration notation that is slithly shorter and gives us a bit more freedom as not make part of the regular top-to-botom flow of control. In this case, the function keyboard is at the star of the stament. EX: function square (x) { return x * x;}. The third is the Arrow function, that is not part of this course.

  2. Each binding has a different scope, that is the part of the code that the binding is visible. let and const binding have a local scope. they are just visible inside the block they ve been defined. var binding has global scope and can be seen for the whole program.

  3. A pure function is a specific kind of value producing function that doesn’t rely on the side effects of other code. It is some kind of independent and don’t interact with global binding. Always that is called with the same argument, produces the same value.

1 Like
  1. To create a Function you declare an expression with the Keyword function.
  2. Let refers to local scope (inside current block)
    Var refers to global scope and remains the same until changed.
  3. A Pure Function is a function that produces a value and does not produce or rely on any side effects.
1 Like

How can you create a function in Javascript?

Use the key word “function,” set the parameters and the function’s logic. For example:

function adder(a,b){return a + b;}

What is the difference between var and let in regards to scope?
let declares functions within a block, so other areas of the code cannot “see” the value. var would create a value visible throughout the whole function it is in, or the global scope.

What is a pure function?
A value producing function that has no side effects and doesn’t rely on side effects of other functions (i.e. values that might change).

1 Like

How can you create a function in Javascript?

A function definition is a regular binding where the value of the binding is a function.

const square = function(x) {

return x * x;

}; 

 console.log(square(12));

 // → 144

What is the difference between var and let in regards to scope?

as I read it var is old style 2015 JS, and are visible on the global scope, where let and const is only visible on local scopes.

What is a pure function?

A pure pure function doesn’t produce or rely on side effects, avoids reading global bindings.


Remember to visit my shop and get cool crypto gear at https://thecryptogearshop.com/

edit: @ivga80 - link ok!

1 Like
  1. The function is created by declaring the function declaration. In terms of structure, it is like this: the function keyword goes first, then goes the name of the function, then, if needed a list of parameters between the parentheses, and finally, the code of the function, also named “the function body”, between curly braces.
  2. let gives you the privilege to declare variables that are limited in scope to the block, statement of expression. var is rather a keyword that defines a variable globally regardless of block scope.
  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 Like
  1. It must start with the word function followed by () to define the function.
  2. A let function will only work in the local block in which they are declared in. A var variable is visible and recognized globally not only in the current block.
  3. A pure function is a specific value producing function with no side effects and it also doesn’t rely on any other side effects from other functions in order to work properly.
1 Like
  1. A function in JavaScript is created with an expression that starts with the keyword funtion.

  2. The difference is that var is visible throughout the whole function, so it is a global binding, and let is only visible to the block in which it is declared in, making it a local binding.

  3. A pure function is a value-producing function that doesn’t have side effects or rely on side effects from another code.

1 Like

Glenn_CostaRica

1.How can you create a function in Javascript?
In JavaScript, you create a function by implementing code that uses certain type of expressions, initiating with the expression function, by indicating with round brackets if the function has parameters (values that it takes as inputs) or not, and by indicating the start and end of its body through curly brackets. The basic structures looks like this
function nameOfFunction(parameters){
instructions;
}

2. What is the difference between var and let in regards to scope?
The “scope” is the section of the entire program, or the subset of instruction, where some binding (variable with its value) is “alive” and usable. When one uses the expression var to create a variable, the scope of this variable will be global, which means this value will be usable withing all the blocks code inside a function. The expression let, on the other hand, declares a variable inside a local block or inside one single subset of instructions.

3. What is a pure function?
These are functions that execute some code independently from the rest of the program, generating the same output from a given input. Pure functions do not produce side effects either.

1 Like
  1. A function in JavaScript is created with an expression “function”, and then giving it some parameters in () brackets. After that comes the body of the function wrapped in braces to be executed when the function is called upon.

  2. “Var” bindings are visible throughout the whole function they appear in, whereas “let” bindings appear only locally in the block they are declared in.

  3. A pure function doesn’t produce any side effects or rely on any.

1 Like
  1. To create a function in JavaScript is by using a keyword function the giving it a parameter.
  2. Variables that are limited to block such as (for,white,if and etc)
  3. Pure function doesn’t have any side effects and doesn’t rely on other code.
1 Like