Functions - Reading Assignment

  • How can you create a function in Javascript?
    It is a block of statements enclosed between { and } and preceded by the function reserved keyword.

  • What is the difference between var and let in regards to scope?
    Let define local variables within the scope of a block. Var is used to define global variables (outside any function) or local variables (to a function).

  • What is a pure function?
    It is a function with no side effects, it only returns a value and once executed, its context/scope is destroyed. It’s 100% reproducible, for the same input, it always get the same output.

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

By using the keyword “function” following by the variable name for the function, optional parameters within parentesis and then brackets including an expression.

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

var elements are global in the scop, while let are just set at current block level (like within a function).

  1. What is a pure function?

A pure function doest not produce any side effects, and returns always the same value.

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

A function is created by using the function keyword, follow by the name of the function, with or without a list of parameters that enclosed in parentheses, follow the function body which is a statement or set of statements enclosed within a set of curly brackets to perform specified tasks.

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

A var is a global variable that is accessible and visible to the whole program even inside any function blocks. The let variable is limited to the scope within the block that they are declared in. They are not accessible and visible to the codes before and after it’s block of code.

  1. What is a pure function?

A pure function returns a value the same output if the same arguments are passed. It must only depend on its input arguments and should not have side effects on any state or data changes during a program execution that may exist outside it function.

1 Like
  1. How can you create a function in Javascript?
    A function is created with an expression preceded with the keyword ‘function’.
    Eg: const var = function([optional parms]){expressions; optional return}

  2. What is the difference between var and let in regards to scope?
    let (and const) are local to the block they’re bound in. Var is common to the whole function or global if not defined within a function.

  3. What is a pure function?
    It is a specific type function that, given the same inputs always returns same outputs and it has no side-effects.

1 Like

Function Reading Assignment Answers

  1. A function is created in javascript with an expression that starts with the keyword function, followed by the naming of the function we are declaring, we set parameters in between two parentheses and define the function within its body. for example:

function add(x, y){
return x + y;
}
we can then pass call and pass arguments to this function. like so:

add(10,10);

//resulting in 20 at the output.

  1. Bindings declared with “let” are in fact local to the block they are declared in. while the pre-2015 Javascript bindings created with the var keyword are visible throughout, they are function scope, NOT block scope.

  2. 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. A Javascript function consists of a block of code that is meant to perform a specific task. A function is defined with the function keyword and then followed by a name and parentheses. The Parentheses contains parameters to send to the function, and is then followed by brackets which contain the code to execute in the function.
  2. Let declares variables that are limited to the block, statement, or exspression in which it is used. Var creates global variables, unless they are within a function where they will be treated as local.
  3. A pure function if given the same input will always return the same output without side effects. Pure functions are independent of outside state and do not alter external states. They are therefore easy to move around and reuse in a program, or in other programs.
1 Like
  1. A function is created with an expression that starts with the keyword function
  2. Binding declared with let is in fact local to the block and var are visible
    throughout the whole 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 Like
  1. A function is created with an expression that starts with the keyword function.
  2. Bindings declared with let are 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.
  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. How can you create a function in Javascript?
    A function is created with an expression that starts with the keyword function, has a set of parameters and a body, which is a collection of statements to be executed when function is called.
  2. What is the difference between var and let in regards to scope?
    Bindings declared with var have a global scope, while those with let have a local scope.
  3. What is a pure function?
    It is a value-producing function that has no side effects and doesn’t rely on side effects from other code.
1 Like
  1. defined by the keyword ‘function’ followed by pair of parenthesis which will include parameters then followed by the function in curly braces
    2)A binding is localized to the block in which it was declared. a binding that was declared a var is in the whole function and through the global space.
  2. A pure function is one that doesn’t have any side effects or rely on side effects from other code. it will always produce the same value if the same inputs are entered
1 Like
  1. With an expression that starts with the keyword function, a set of parameters, and a body, which contains the statements that we want to be executed when the function is called.
  2. let creates a binding that is visible only to the function in which it is created. It is local.
    var creates a binding that is visible throughout the whole code. It is global.
  3. A pure function is a specific kind of value-producing function that doesn’t have side effects and is not affected by side effects from other code.
1 Like

1. A function is created with an expression that starts with the keyword function. It has a set of parameters and a body, which contains the statements that are to be executed when the function is called.
2. The two keywords let and var function on different scopes, the let function is local while the var function is a global function that can be referenced throughout the entire code.
3. A pure function is a specific kind of value-producing funciton 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.

1 Like
  1. by typing: function(){}. Can be with or without parameters and if there is any that goes into the (). The actual action that we are expecting must be described within the body which is between {}.
  2. when “let” is declared within the function, it only works within the function and the global code doesn’t understand it. when “var” is declared it can be globally understood.
  3. a pure function doesn’t read any global values and executes the same way every time (given the same parameters)…
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.

  2. 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.
    Functions created with 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 function that doesn’t have any side-effects and doesn’t rely on side-effects from other code. It has the property that it always produces the same value if the same inputs are passed.

1 Like
  1. Create a function by using the Keyword Function then apply a name to the function, declare parameters in Parentheses () and finally between curly brackets you have the code that the function will execute when called. A single variable can become an entire function. => Arrow functions are also an option

  2. A binding outside a function can be global(whole program) or Local (inside a function).
    let has a local scope to the block they are declared in and can not be seen outside the local block.
    var visible thru the whole function it is in, or globally thru the whole program as long as it’s not in the function.

3.A pure function is a function that produces a value that has no side effects but also doesn’t rely on side effects from other code

1 Like
  1. How can you create a function in Javascript?
    By using the keyword “function” in an expression that contains paramters and a body with a statement which will be executed.

  2. What is the difference between var and let in regards to scope?
    While “let” bindings are only visible in local bindings, the “var” bindings are visible a callable even outside of the function.

  3. What is a pure function?
    A pure function is a value-producing function which has no side effects and cant be effected by other code.

1 Like
  1. How can you create a function in Javascript?
    Start with the Keyword “Function” and a body which contains the statements to be executed

  2. What is the difference between var and let in regards to scope?
    Bindings declared by “let” and “constant” are local to the block they are declared in while “var” bindings are visible throughout the whole function 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 specofoc kind of value producing function that has no side effects and is not affected by other code.

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

writing the key word function and then the name of the function, the parameters and finaly what will the function do.

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

var is set for the hole program and let is specific for a part of the program.

  • What is a pure function?

one that will give the same output for a same input.

1 Like
  1. A JavaScript function is a block of code designed to perform a particular task. A JavaScript function is executed when “something” invokes it (calls it).
  2. The Var function lasts for the entirety of the code. The Let function is like Var as well with almost no difference except that the Let function is only a variable for the code that is between {}. So the Let variable has a smaller scope, where as at the Var function last throughout. Let =small scope. Var = large scope.
    3)In computer programming, a pure function is a function that has the following properties: Its return value is the same for the same arguments. Its evaluation has no side effects. Thus a pure function is a computational analogue of a mathematical function.
1 Like
  1. How can you create a function in Javascript?
    you can create a function with the keyword function
  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. var instead has global binding and is considered in and out of the 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—for example, it doesn’t read global bindings whose value might change.
1 Like