Functions - Reading Assignment

  1. How can you create a function in Javascript?
    To create a function start with keyword as an expression. Then add the set of parameters and then the body which are statements to be executed when the function is called.

  2. What is the difference between var and let in regards to scope?
    Let is local to the the block, usable within the block but var is global throughout the block

  3. What is a pure function?
    A pure function is a specific function that produces value and does not have side effect nor relies on side effects from other code. It will always produces the same value when called using the same arguments.

1 Like
  1. A function is created with an expression that starts with the keyword “function”. It can also be created with an arrow “=>” after the parameters.

  2. var is global and is visible throughout the whole function it is declared in or the global scope of not declared in a function. let is local to the block it is declared 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. You can create a function as a definition, example : const square = function(x), as a declaration ie function square (x) or an arrow function ie const square = (x) =>

  2. Var is used for global bindings ie bindings that exist for the whole program and LET is used for local ones so only the block of code within the same braces

  3. A pure function is a function that has no side effects and doesnt rely on side effects from other code. It always returns a value.

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

const name = function(x) {
body/statements that are to be executed when the function is called;
}

or

function Name(x) {
return x * x;
}

or

const Name = (x, y) => {
return x;
}

  1. What is the difference between var and let in regards to scope?
    When you declare a variable with var it is available in the global scope
    When you declare a variable with let it is available in the local scope
  2. 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. const foo = function() {};
  2. Bindings declared with the var keyword are visible throughout the whole function that they are declared in, or throughout the global scope otherwise. Bindings declared with the let keyword are local to the block that they are declared in.
  3. A value producing function that has no side effects and doesn’t rely on side effects from other code.
1 Like
  1. We can create a function in JavaScript by binding variables to values ​​of ‘function type’ and also by directly declaring a variable name as a function with its value.

  2. The var keyword provides ‘global scope’ if declared outside of a function, or ‘local scope’ if declared in the body of a function. The let keyword limits the range of a variable to the block in which it was created (‘block scope’).

  3. Pure functions are those that produce values ​​from their parameters without depending on the side effects of other code. They are predictable functions, easy to test, as they are always called with the same arguments, producing the same value.

1 Like
  1. How can you create a function in Javascript?
  • We start with the ‘function’ keyword.
  • We add the parameters we want, or no parameters (also called arguments).
  • We add the statements that we want to execute when the function is called.
  1. What is the difference between var and let in regards to scope?
    let (and const) are seeing by a function’s local scope. These are bindings declared inside functions.
    vars are seeing on the global scope. These are bindings defined outside of any function or block.

  2. What is a pure function?
    A function that is called only for its return value, and not for its side effects. A pure function has no side effects and 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” followed by a set of parameters and a body (which must always be wrapped in braces) and contains statements executed when the function is called.

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

Bindings declared with let and 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.

In pre-2015 JavaScript, only functions created
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.

  1. What is a pure function?

A block of code that always returns the same result if the same arguments are passed. It does not depend on any state, or data change during a program’s execution rather it only depends on its input arguments.

1 Like
  1. Function in Javascript is created with an expression function that is followed by a set of parameteres and body which contains statements executed when the function is called upon.

  2. The difference between those two functions are that “var” function operates on a global scope ( bindings that exist for the whole program ) while “let” function operates on a local scope ( meaning it only operates on the block of code withing the same braces ).

  3. Pure function is a function that is producing value and doesen’t have side effects or relies on one from other code.

1 Like
  1. You can define a function by making an expression that starts with the keyword “function” and is followed with a set of parameters in “()” and a body in “{}”. A function is a value type and you assign it to a binding just like any other value. You can also declare a function by putting the keyword “function” at the start of the statement and then the binding, followed by the parameters and the body. This way of creating a function has the advantage that you can call the function even if it is positioned below the position from where you make the call.

  2. “var” is function scope, “let” is block scope. Function scope is within the function, block scope is within curly brackets. Both are global if they are defined outside of any block or function.

  3. It is a function that has no side effects, does not rely on side effects from any other function and that does not read any global bindings that may change. A pure function always returns the same output for any given arguments.

1 Like

-Can be created with an expression beginning with a keyword function. A function key word when used as an expression can create a function value. If used as a statement, it can be used to declare a binding and give it a function as its value.

-The main difference between let and var is that scope of a variable defined with let is limited to the block in which it is declared while variable declared with var has the global scope.

-A pure function means when a same input is passed every time, the function will return the same output.

1 Like
  1. How can you create a function in Javascript?
  • 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 and const are in fact local to the block that they
    are declared in. 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
  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. It doesn’t read global bindings whose value might change
1 Like
  1. A function in javascript is created with an expression that start with a key word function. A function has a set of parameters() and a body which contains statements are to be executed when the function is called.
  2. Let is local to the block that it declared in and if we declared inside a loop, the code before that and after that can not see it. For var is an old style binding and it is visible through out the whole function as it appeared in.
  3. A pure function is a special kind of value-producing that not only has no side effects, but does not rely on side effects from other codes.
1 Like
  1. 3 way:
  • function name(parameters){execution};
  • name = function(parameters){ execution};
  • name = (parameters) => {execution};
  1. let allows you to declare variables that are limited in scope to the block, statement, or expression on which it is used. var keyword defines a variable globally, or locally to an entire function regardless of block scope.
  2. pure function does not change any information from global scope as well as not receive any parameters
1 Like
  1. A function is created with an expression that starts with the keyword function.
  2. var creates global bindings, let creates local bindings
  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. 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. How can you create a function in Javascript?
    A function is created with an expression that starts with the keyword function then a set of parameters ()

  2. What is the difference between var and let in regards to scope?
    var is applied to the global scope, but can be seen inside the local scope, whilelet is applied to the local scope, and not seen outside of that block.

  3. What is a pure function?
    A pure function is a specific kind of value producing function that not only has a NO side effect, but also doesn’t rely on side effects from any other code.

1 Like
  1. How can you create a function in Javascript?
    const newFunction = function(x,y) {some code;};
  2. What is the difference between var and let in regards to scope?
    bindings declared with var are visible to the global scope (if not called inside a function), and let is local to the block it is declared in
  3. What is a pure function?
    a value-producing function that has no side-effects and does not rely on any other part of code outside it

1.You create a function in Javascript with an expression that starts with the function keyword
2. Let is local scope to the block and is not seen outside of it while var is global scope to the block
3. A pure function is a value producing function with no side effects and does not rely on global binding

1 Like
  1. How can you create a function in Javascript?
  • A Javascript function is a block of code designed to perform. particular task. This is defined with the function keyword, then name, then parenthesis.
  1. What is the difference between var and let in regards to scope?
  • When considering scope, (let) declares a variable limited to the block, statement, or expression on which it is used. (var) however defines a variable globally, regardless of block.
  1. What is a pure function?
  • A pure function is a function when given the same input will always return the same output, additionally, it will contain no side effects. They are completely independent of outside states, do not alter any external states, easy to move around and reuse throughout a program, and have great use in future adaptations.
1 Like
  1. We create functions by using the expression “function” followed by space and then the name of the function followed by open and close parenthesis, in the middle of which we can define paramenters. The body of the function is enclosed in braces.
  2. A binding declared with var is seen globally while with let and const, the binding gets a local scope.
  3. Pure functions are those that do a very simple task and use bindings that do not depend on other global bindings.
1 Like