Functions - Reading Assignment

1- A function is defined using the keyword function, followed by name, followed by parentheses containing the arguments of the function, followed by the body of the function with curly brackets.

2- A binding declared with let is local to the block it is declared in. A binding declared with var is visible throughout the whole function or throughout the global scope, if it is not in a function.

3-A pure function is a value producting function that can be subsituted with its return value without changing the meaning of the code. A pure function does not product a side effect and does not rely on global binding that may change. When called with the same arguments, it always produces the same value.

1 Like
  1. By using the keyword “function”, which then is followed by a set of parameters (it could even have 0 parameters) and a body containing the statements to be executed upon calling of the function.
  2. Let is a local binding, meaning that it refers only to the function it is defined in, while var is a global binding that can be called upon throughout the entire program.
  3. It is a function that produces values which do not impact on the rest of the program and do not rely on other code. It is useful because a value inserted in such function will always produce the same result. Hashing is probably assimilable to some extent to such category of functions.
1 Like
  1. How can you create a function in Javascript?
    A function is created with an expression that starts with the keyword function. It is the parameter and the body which creates a statement.

  2. What is the difference between var and let in regards to scope?
    var keyword, are visible throughout the whole function that they appear in—or throughout the global scope, if they are not in a function. Var is different then all program.

  3. What is a pure function?
    The function always return the same result if the same arguments are passed on. It does not depend on any state or data, change during a program’s execution.

1 Like

1, It is created with an expression that starts with a keyword function. It has a set of parameters and a body, which contains the contains the statements that are to be executed when the function is called.
eg, const square = function(x) {
return x * x;
};
console.log(square(12));
// -> 144.

2, Bindings declared with ‘let’ are ‘local’ to the block they are declared in, so in a loop the code before and after cannot see i. The keyword ‘var’ is visible throughout the global scope.

3, A pure function has the property that , when called with the same arguments, it always produces the same value(and doesn’t do anything else).

1 Like
  1. How can you create a function in Javascript?
    Function declaration:
    function functionName() {
    // function code goes here
    }

Function call:
functionName()

  1. What is the difference between var and let in regards to scope?
    “let” allows you to declare variables that are limited to the scope of a block statement { }.

  2. What is a pure function?
    It has no side-effects and doesn’t rely on a side-effect of another function.

1 Like
  1. A function starts with the keyword function with a name, after that there is a parameter that is always wrapped in braces( function name(x, y) )

  2. Bindings created with the var keyword can “see” everything that is happening in the function(local scope) if it’s in a function or if it’s in the global scope it can see everything there. Bindings with the keywords let and const are not perceivable in the entire function. If you put let or const inside of a loop the other codes will not be able to “see” it, because they are local to the block that they are declared in.

  3. A pure function is a function that produces a specific kind of value that doesn’t use side effects and they don’t either use side effects of other codes. Pure functions depend on the same input argument, the value never changes if the argument is the same.

1 Like
  1. By using the key word Function.

  2. In a function let is a binding that limited to the scope of that function. Var is more of a global binding accessible outside and inside of functions.

  3. When a functions output is determined specifically by the inputs that has no side effects.

1 Like
  1. How can you create a function in Javascript?
    Start with the keyword function, and in it, a set of parameters:
    function(a,b,c)
    A name may also be assigned to the function:
    const sum = function(a,b,c) { return a+b+c; ); or
    function sum(a,b,c) { return a+b+c; )

  2. What is the difference between var and let in regards to scope?
    var is global while let is local to the block.

  3. What is a pure function?
    A pure function has no side effects and always returns the same result if the same arguments are passed in. It does not depend on side effects.

1 Like
  1. To create a function in Javascript you simply type the word function followed by parentheses. The values you put into it are completely determinant on what you wish to do thereafter.

  2. In terms of scope, the difference between a variable and let is that a variable is a global thing within the code. This means that once it is defined it is defined throughout the entirety of the code, as long as it is not being defined within a function. Let is only defined within that more localized area of the code (or what would be called a block in programming jargon).

  3. A pure function is a value producing function which produces no side effects and does not rely on global bindings.

1 Like
  1. A function is created with an expression that starts with the 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.bal.
  2. A binding declared by Let is local to the block, so if it is created inside a loop the code before and after can’t see it. Bindings created with Var are global.
  3. A pure function is a value producing function that has no side effects and doesn’t read global bindings whose value might change. When called with the same arguments it always procuces the same value.
1 Like

1. How can you create a function in Javascript?

You create a function in javascript by putting parentheses after an expression that produces a function value

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

In terms of scope, the difference between var and let is functions created with the var keyword are visible throughout the whole function that they appear in, while let is only visible inside of a block.

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 Like
  1. You can create a function in JS by using the “function” keyword or “=>” to declare a function.

  2. Var bindings can be seen and used by the whole program unlike let, which can only be used and seen within the context of the box it is written in.

  3. A pure function does not create any side effects nor does it rely on any side effects produced by other functions. It does not use any global bindings, as they could change their value, which means a pure function will always return the same result when given the same arguments.

1 Like
1. How can you create a function in Javascript?
A function is created with an expression that starts with the 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.  The function body of a function created this way must always be wrapped in braces, even when it consists of only a single statement.   

2. What is the difference between var and let in regards to scope?
Bindings declared with let and const 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.  Only functions create new scopes, so old-style 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.

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 Like

1 Uma função é criada através de uma keyword, parametros (que podem ser ausentes, unico ou multiplos) e o corpo, sendo que existem diferentes formas de elaborar/organizar os 3 elementos na função.

2 Let e Const sĂŁo keywords utilizadas para bindings locais, ou seja todos os bindings estabelecidos dentro de um bloco serĂŁo restritos somente a ele.

Var é uma keyword utilizada para bindings globais, portanto podem ser alteradas dentro de uma função.

3 É uma função independente de outras funçÔes, portanto previsĂ­vel e nĂŁo dependente de efeitos de lado de outras funçÔes ao mesmo tempo que ela tambem nĂŁo produz efeitos de lado em outras funçÔes.

1 A function is created using a keyword, parameters (which can be absent, single or multiple) and the body, and there are different ways to elaborate / organize the 3 elements in the function.

2 Let and Const are keywords used for local bindings, that is, all bindings established within a block will be restricted to it only. Var is a keyword used for global bindings, so it can be changed within a function.

3 It is a function independent of other functions, therefore predictable and not dependent on side effects of other functions at the same time that it also does not produce side effects in other functions

1 Like

1. How can you create a function in Javascript?
You create a function using the keyword ‘function’ and creating a function name. Parenthesis follow including any variables for the function. Curly braces follow including the task that you wish to perform on the variables i.e.

function reuseableFunction(a, b) {
console.log(a + b);
}

To call the function simply call the function name (reuseableFunction)and add any variable values i.e

reuseableFunction(20, 50);
// —> 70

2. What is the difference between var and let in regards to scope?
Variables created using ‘let’ are set to the local environment/block of code. This is a local scope variable and used most. Variables set using ‘var’ have global scope and read outside of the current function/environment/block.

3. What is a pure function?
A pure function is deterministic in its calculations/function creating no side effects and affected by NO side effects of other code / functions. A pure function does not read global bindings where values might alter.

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

A function is created with an expression that starts with the keyword function

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

Bindings declared with let are local to the block of code that they
are declared in and var is visible throughout the whole function that they appear in—or throughout the global scope, if they are not in a function.

  1. 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 Like
  • How can you create a function in Javascript?
  • What is the difference between var and let in regards to scope?
  • What is a pure function?
    A function is created with the keyword “function” – example:
    function calculateRisk(){
    // statement(s)
    return(value);
    }
    A function can also be created using => to save time and textage.
    A function can have a side-effect or can return a value. Functions allow code to be packaged into concise bundles of functionality. After the function is created, it can be reused, making coding simpler as the library of functions grows.
  1. let is used to declare variables in a function and is limited in-scope to the block and nested blocks, where a block is what is located between the {}. Functions called within the function cannot access let-defined variables.
    var defines variables that are scoped to the function they are in, and can be used within the function or globally if they are defined outside a function.
  2. What is a Pure Function? A pure function always produces the same output given the same inputs (like a hash function), it produces no side-effects, and the arguments passed into the function cannot themselves be modified.
1 Like
  1. With the keyword function, wich is given a name.
    ex. function howMuch(x,y) {return x+y}
  2. var is visible in and outside the scope, let is only visible inside the scope
  3. A pure function is a value-producing function that has no side effects and doesn’t rely on side effects
    from other code, it does not use global values.
1 Like
  • How can you create a function in Javascript?
    You begin with the keyword function followed by parameters in brackets and then the body which contains a statement to be executed when the function is called.
  • What is the difference between var and let in regards to scope?
    let is local so is only visible to the block it is contained in whereas var is visible anywhere in the the program so is global.
  • What is a pure function?
    It is a value-producing function which doesn’t have any side effects or rely on the side effects from other code.
1 Like

1 FUNCTION followed by function name and parenthesis (may or may not including arguments) followed by the block code that we want that function to execute.
2. LET is block scoped whereas VAR is function scoped.
3. Function that is only dependent on input arguments at max, and not dependent on side effects.

1 Like