Functions - Reading Assignment

  1. How can you create a function in Javascript?
    keyword function, define parameters in (), define body in {}

  2. What is the difference between var and let in regards to scope?
    let & const bindings are local to the block they’re declared in.
    var bindings are global unless they are declared within a function.

  3. What is a pure function?
    A function which does not produce side effects nor relies on side effects from other code.

1 Like
  1. How can you create a function in Javascript?
    Write function, followed by a name you give the function and put parameters in parentheses. Then in between brackets you write what you want the function to do.
    Example:
    function square(x) {
    return x * x;
    }

  2. What is the difference between var and let in regards to scope?
    var keyword has a larger scope as they are visible throughout the whole function that they appear in or throughout the global scope, if they are not in a function.
    let keywords are smaller in scope in that they are local to the block that they are declared in.

  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 by using the “function” keyword. A function must also have a name and it can have parameters. Each function also has a block which contains the actions that a program takes once the function is called.

    Example:
    const functionName = function(argument1, argument2) {the statements to be executed when the function is called}

  2. Variables declared with “var” are visible in the entire program, but if a variable is declared with “let” it is only visible in the block that it was called in (it’s a local binding).

  3. A pure function is a function that doesn’t depend on any global bindings and it will always return the same result if called with the same arguments.

1 Like
  1. You have three methods
  • You can create a function by binding a ‘function value’ to a variable. E.g. const a = function(b) {};
  • You can declare a variable as a function E.g. function myFunction(param){body}
  • You can use arrow notation e.g. const a = paramater(s) => do something
  1. var is accessible globally - so it can be invoked outside of the body of your function, where let is local scope only.

  2. Pure function are only value returning and do not require the side effects of other functions to produce that value.

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. Function body must always be wrapped in braces.
  1. What is the difference between var and let in regards to scope?
  • if you create let and const inside of a loop, the code before and after the loop cannot see it.
  • bindings created with var are visible throughout the global scope if they are not in a function.
  1. What is a pure function?
  • a specific kind of value-producing function that not only has no side effects but also doesn’t not rely on side effects of other codes.
  • for example it doesn’t read global bindings whose value might change
2 Likes
  1. By Defining:
const eg = function(x) {
console.log(q + x);
}

OR

By Declaring:

function eg(h, j) {
return h / j + 72;
}

OR

Using Arrows:

let z = k => k % 3;
  1. let is a binding which is global, meaning that it is subject to change, whereas var is a local binding, which is constant to its own block.

  2. A pure function is a function that executes without any side-effects and whatever it invokes in one environment, will always be the result in another environment. These functions also don’t change based on the side effects of other code.

1 Like

*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 (in this case, only x) and a body, which
contains the statements that are to be executed when the function is called
ex:const square = function(x) {
return x * x;
};

  • What is the difference between var and let in regards to scope?
    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. 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.
  • 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. 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?
    You create a function with an expression that begins with the keyword function Functions will have a set of parameters and the body contains statements to be executed when the function is called.

  2. What is the difference between var and let in regards to scope?
    let is blocked scoped and var is scoped to the current execution context, which is the variables enclosing function or the global scope.

  3. What is a pure function?
    A pure function is a value-producing function that not only has no side effects, but also doesn’t rely on side-effects from other code. When called with the same arguments it produces the same values.

1 Like
  1. How can you create a function in Javascript?
    a function is created with an expression that starts with the keyword function
    const square = function (x) {
    return x *x;
    };
    console.log(square(12));
    //144

  2. What is the difference between var and let in regards to scope?
    Let are local to the block that they are declared in , so if you create one of those inside a loop the code before and after it cannot see it. Var keyword are visible throughout the whole function they appear in or global scope.

  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 doesnt rely on side effects from other code, like reading global bindings whose value might change.

1 Like
  1. Start by using the keyword function then go on to denote the parameters and specify the statements to be executed in the body.

  2. The difference is determined by their placement. Those placed outside the function body are global while those within the function body are local. Making use of the different terms can help keep code the code easily understood.

  3. A pure function is a function that provides it’s return value without creating, or relying on, side effects.

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 functions is called.”

  2. What is the difference between var and let in regards to scope?
    –>
    var: global scope.
    let: local scope.

  3. What is a pure function?
    –> It’s a function that it’s executed only in local scope, it does not have side effects and it’s not affected by side effects from other codes.

1 Like
  • How can you create a function in Javascript?
    With the function keyword followed by a name followed by parentheses containing input to the function, followed by curly braces which contain the statements of the function!
    Is there any other keyword aside function functionName(variableone) {}; to create a function?
  • What is the difference between var and let in regards to scope?
    Var has a wider scope, global scope to the program, let has a smaller scope limited to the function or block of code it is called in
  • What is a pure function?
    A pure function always return the same output for the same input, and produces no side effects.
2 Likes
  1. How can you create a function in Javascript?

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.

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

Var is function scoped and let is block scoped. “Block scoped” means that the code before and after the loop cannot “see” the information for that piece of the code.

  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
  1. How can you create a function in Javascript?
    A function is an expression, which starts with the keyword function.
  2. What is the difference between var and let in regards to scope?
    let is local to the binding it is located in, var apply to the whole function.
  3. What is a pure function?
    It is a value-producing function that produces no side effects and also doesn´t rely on side effects from other code.
1 Like
  1. A function is created with an expression that starts with the word function
  2. var defines a variable that can be seen outside of a certain argument while let is only used within the argument
  3. A pure function only depends on its input arguments
1 Like

How can you create a function in Javascript?

  • Functions have a set of parameters.
    *They are created with the keyword “function”, they have a body which contains the statement to be executed, and a “return” statement that determines the value of the function return.

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

Var is visible throughout the whole function, while let is only visible inside the loop that they were created in.

What is a pure function?

Is a value producing function that has no side effects and does not rely on side effects from other functions.

1 Like

1. How can you create a function in Javascript?

Function is created with an expression that starts with keyword function, the function have sets of parameters and body the body must be always wrapped in braces.

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

Binding declared with let are local they are not visible.
Binding declared with var keyword are visible throughout the whole function or throughout
the global scope if they are not in function.

3. What is a pure function?

Value-producing function that has no side effects and does not rely on side effects from other code.

1 Like
  1. How can you create a function in Javascript?
    function functionName (parameters) { body of function }

  2. What is the difference between var and let in regards to scope?
    let bindings are local bindings, hey can only be used the block that they are created in. Where var bindings are globle visible throughout out the whole function.

  3. What is a pure function?
    pure function is when the function is called with the same arguments it always produces the same result.

1 Like
  1. How can you create a function in Javascript?
    • Const “binding” = function(x) {……}
      • Expression with keyword function
        • Set of parameters e.g x,y,z
          • Body, which contains the statement to be executed once function called
            • {} braces always required only if single statement
  2. What is the difference between var and let in regards to scope?
    * let - local scope
    * var - global scope
  3. What is a pure function?
    * Specific kind of value-producing function that not only has no side effect but also doesn’t rely on side effects from other code
    * Eg it doesn’t read global bindings whose value might change
1 Like
  1. starting with the function keyword, then a name followed by (parameters) and last a body with instructions {…}
  2. let can be limited to a block. var can be a global scope variable.
  3. a function that always produces same value without changing the code. and regardless of changes in global bindings.
1 Like