Functions - Reading Assignment

  • How can you create a function in Javascript?
    A function is created with an expression that starts with the keyword function. Functions may or may not have a set of parameters.

  • What is the difference between var and let in regards to scope?
    var is visible in the clobal environment and let is only seen in the local environment

  • What is a pure function?
    A pure function is a specific kind of value-producing function that only has no side effects but also dos not rely on side effects from other code.

1 Like
  1. after function write name of function, then its parameteres in () and what functions does in {}
  2. var is scoped globally, let locally
  3. function with no side effects and it does not rely on outputs from other functions
1 Like
  1. A function is created with an expression that starts with the keyword function () .

  2. Bindings declared with let keyword are local to the block that they are declared in. While bindings declared with the var keyword, are visible throughout the whole function that they appear in—or throughout the global scope.

  3. A pure function is a deterministic function. This means when same input is passed every time, the function will return same output. In mathematical terms it is nothing but a well defined function.

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.

  1. Let is 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 bindings are visible throughout the whole function that they appear in—or throughout the global scope, if they are not in a function.

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

1 Like
  1. By using the keyword function as the expression
  2. let is local to the to the block that that they are declared in, code before and after the loop cannot see it. var bindings are visible in the whole function in which they appear.
  3. A pure function with the same input, will always return the same output and Produces no side effects
1 Like

1. How can you create a function in Javascript?

To create a function in JavaScript you can use the keyword function followed by an expression, 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?

  • 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.

3. What is a pure function?

A pure function is a function that given the same input will always return the same output and it produces no side effects.

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

by binding
const functionName = function(parameter1, parameter2…parameter n){
//variables
//expresions
//loops
}

by declaration
function functionName(parameter1, parameter2…parameter n){
//variables
//expresions
//loops
}

arrow functions
const functionName = (parameter1,parameter2…paramenter n) =>{
//variables
//expresions
//loops
}

  1. What is the difference between var and let in regards to scope?
    let is local to her block for example local for a loop for or while loop
    var is global to her function or the whole program
  2. What is a pure function?
    A function that does not have side effects and don’t depend on side effects for other functions or global variables
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 (in this case, only x) 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. A function can have multiple parameters or no parameters at all.

  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. 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.

  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. 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). A call to
    such a function can be substituted by its return value without changing the
    meaning of the code. When you are not sure that a pure function is working
    correctly, you can test it by simply calling it and know that if it works in that
    context, it will work in any context.

1 Like
  1. How can you create a function in Javascript?
    = A function is created with an expression that starts with the keyword function.

  2. What is the difference between var and let in regards to scope?
    = Let is local in the block it is declared in. Var are visible throughout the whole function they appear in or through the global scope if not in a function.

  3. What is a pure function?
    = A pure function is a value producing function with no side effect and who doesn’t rely on any side effects from other code. For an example it does not read global bindings, when called with the same arguments it always produce a the same value.

1 Like
  1. How can you create a function in Javascript?
    Function Name(variable) {
    function/how to modify variable }
  2. What is the difference between var and let in regards to scope?
    Let is used for a specific section of code, while var will be distributed throughout the whole program.
  3. What is a pure function?
    It is a function that doesn’t rely on any sort of outside information(IE time or random number generator.) If given the same input it will always have the same output.
1 Like

1. How can you create a function in Javascript?
By using FUNCTION()

2. What is the difference between var and let in regards to scope?
LET applies to the current block only while VAR applies beyond the current block

3. What is a pure function?
A function that 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?
    It is a binding, where the value of the binding is a function.

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

  • var is used to give a value to a binding that applies globally in the program
  • let is used to define a binding only locally in a block or 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
  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 (in this case, only x) 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?
    • A Var can be used globally at any time.
    A let can only be used locally

  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.
    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. 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 execute when the function is called.

  2. Bindings declared with “let” are local to the block they are declared, the before and after code in the loop can not see it.
    Bindings declared with “var” are visible throughout the whole function or throughout the global scope.

  3. A pure function is a function which given the same input, will always return the same output and produces no side effects.

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. The function body of a function created this way mist always be wrapped in braces, even when it consists of only a single statement.

const f = function(a) {
console.log(a + 2);
};
||
function g(a, b) {
return a * b * 3.5;
}
||
let h = a => a % 3;

  1. Var regards to the global execution stack where as let regards to the scope inside its function.\

  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 for example, it doesn’t read global bindings whose value might change

1 Like

1. How can you create a function in Javascript?
A function is created with an expression that starts with the keyword function
2. What is the difference between var and let in regards to scope?
with let is 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 where 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 will always give the same result with the same parameters

1 Like

1. How can you create a function in Javascript?
You can create/construct a function using Javascript code language. The Javascript function is a block of code arranged to perform a specified task. This code is executed when called for or invoked to do so. The function construct or flow consists of first, the "function" keyword, then an ensuing "name", and finally parameters are nestled or not within "parentheses ()".

function name (parameter1, parameter2, parameter3) {
code declaration/execution
}

2. What is the difference between var and let in regards to scope?
The difference between a var and a let statement made within the scope of a function, is that, a declared var is recognized globally, regardless of its location. A let or a const statement, on the other hand, is completely restricted to its local block. This is called block scoping. These are often referred to as a block or enclosed scope.

3. What is a pure function?
Pure functions are exempt from side effects due to executing an identical input output task. They always consistently return the same result. Pure functions also operate independent of any outer state by avoiding reading global bindings. Therefore such states (outside) are not modified by this functions execution. The key benefit is this function is easily movable or can even be reused throughout a program. This allows for flexibility in later function writing reducing the need for additional rework.

1 Like
  1. How can you create a function in Javascript?
    Defining a name the function’s parameters and the code executed by it.
    function name(parameter1, parameter2, parameter3) {code to be executed}

  2. What is the difference between var and let in regards to scope?
    The term “let” is used for local bindings where “var” is for global bindings.

  3. What is a pure function?
    A pure function is a function which does not have side effects itself nor does it rely on side effects from other functions. With the same parameters the function always returns the same value.

1 Like
  1. function keyword, anonymous with () and the fat arrow =>
  2. let and var are both used to define variables. var is function scoped and let is block scoped. let can only be seen within the local function, where var can be seen thoughout the program.
  3. A pure function does not use anything from outside the local environment with the exception of its arguments and it either returns 1 or no value.
1 Like
  1. Functions are defined, or declared, with the “function” keyword as seen below:
    function nameOfFunction() {
    Code to be executed
    }
  2. Var is a global and function scoped variable. Var is hoisted to the top of their scope and var can be re-defined. While let is a block scoped variable that is not hoisted and cannot be re-defined.
  3. Pure Functions will always produce same output given the same input and produces no side effect.
1 Like