Functions - Reading Assignment

Hello everyone,

  1. A function is created with an expression that starts with keyword function.

  2. var keyword has a global scope and let keyword has local scope.

  3. A pure function is a function wherein if the input values are the same it returns the same output.

1 Like
  1. How can you create a function in Javascript?
    In JavaScript, a function is created by starting a block of code with the keyword function. Parameter(s) for the function is declared inside the bracket following the function keyword. The rest of the code block forms the body of the function and is wrapped in braces following the parameters. The body consists of codes that are to be executed when the function is called.

  2. What is the difference between var and let in regards to scope?
    Both var and let are used to declare bindings. Bindings declared with let are only accessible by the local block of codes surrounding the declaration, for example inside a function. Bindings declared with var are accessible from anywhere in the program.

  3. What is a pure function?
    A pure function is a function that produces no side effect and return a value without relying on side effects of other 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. Functions have a set of parameters which are listed inside the parentheses in the function definition.
    var x = myFunction(4, 3); // Function is called, return value will end up in x

function myFunction(a, b) {
return a * b; // Function returns the product of a and b
}
The result in x will be:
12




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

The main difference is the scope difference, while let can be only available inside the scope it’s declared, like in for loop, var can be accessed outside the loop for example. … let allows you to declare variables that are limited in scope to the block, statement, or expression on which it is used.





  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 codes.
1 Like
  1. Just by creating an expression that starts with the keyword “function”.

  2. let keyword is used when we want to declare a variable that is limited within the scope of the its block. var keyword is used to define a global variable.

  3. A pure function is a type of function that does not produce any side effects, returning always the same output.

1 Like
  1. Create an expression defined with keyword function, that has a set of parameters and a body. It must be wrapped in braces. Can be a an expression or a declaration.

  2. var is visible throughout the whole function. It is considered global.
    let is local to the block it is declared in.

  3. A pure function has no side effect, always produces the same value and nothing else.

1 Like
  1. define the function with key word function like:
    function somename(par1, …) {
    …
    }
    or use => notation
    (param1, param2…) => {
    …
    }

  2. var is scoped in the function it is in and let is scoped in the block {} its in.

  3. pure function only returns a value and has no side effects and does not depend on anything else that has side effects.

1 Like

1. How can you create a function in JavaScript?

By declaring its parameters and body.

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

var sets the binding globally whereas let sets the binding locally.

3. What is a pure function?

A pure function will always behave as intended without any side effects or variation.

1 Like
  1. You can create a function is JavaScript by the keyword “function” then the parameters of the function is parenthesis.
  2. let is local to the scope and var is global to the scope.
    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—”

Haverbeke, Marijn. Eloquent JavaScript, 3rd Edition (p. 55). No Starch Press. Kindle Edition.

1 Like

Functions - Reading Assignment

  1. A function in javascript can be created with the keyword ‘function’, which contains the statements that are to be executed when the function is called.

  2. The difference between var and let with regard to scope is that let bindings are local to the block that they are declared in. The var function can appear throughout the global scope, if they are not in a function.

  3. A pure function is a specific value producing function that has no side effect and doesnt rely on side effects from other code.

1 Like
  1. A function is created with an expression that starts with the keyword function. They have a set of parameters called arguments and a body which contains the statements that are to be executed when the function is called.
  2. The difference between var and let in regards to scope is that bindings declared with let are local to the block that they are declared in whereas bindings 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. A pure function is a specific kind of value producing function that not only has no side effect but also doesn’t rely on side effects from other codes.
1 Like
  1. How can you create a function in Javascript?
    you can use “function” or “const” keywords followed by “( )” if it includes parameter(s) and then the statements to be run in the body between “{ }”
  2. What is the difference between var and let in regards to scope?
    bindings created with let are only “seen” locally within the function block, while var will be “seen” outside (globally) as well
  3. What is a pure function?
    a pure function doesn’t rely on any side effects from the other program code and doesn’t produce any side effects of its own - it can be tested separate from the rest of the program code as well
1 Like
  1. In JS you can create a function by using 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 and also the body must be wrapped in braces even when it only consists of a single statement.

  2. let is local scope while
    var is global scope.

  3. A pure function is a well defined function, it depends only in its own arguments,
    it won’t try to change variables out of its scope and it doesn’t have any side effects.

1 Like

1. How can you create a function in Javascript?
With an expression that starts with the keyword function, then followed by parameters in () and body {statements to be executed}

2. What is the difference between var and let in regards to scope?
let is local to the block that it is declared in, so if you create one of this inside of a loop, the code before and after the loop cannot “see” it. The var binding are visible throughout the whole function that they appear in - global scope

3. What is a pure function?
It 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 JavaScript function is defined with the function keyword, followed by a name , followed by parentheses ()

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

let and const use block scoping, they won’t appear locally. Var uses the global scope if they are not declared in a function.

  1. What is a pure function?

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.- Using the keyboard ‘function’, giving a name, followed by parentheses that can contain parameters, followed by curly brackets, that contain the body
2.- with let the scope is local to the block where it’s defined, and var has a global scope
3.- Is a function that it will always produce the same results given the same input. It make no usage of global variables

1 Like
  1. a function is a binding. It is created with an expression thats starts with the keyword function. You give the function a name, define parameters in () and a body (which contains the statements which should be executed) wrapped in {}
    image

  2. let and const bindings are local to the block (so the code before and after the block in which they are declared in can not “see” them) - so local scope
    var bindings are visible throughout the whole scope - so global scope

  3. a pure functions is a function that only produces values and no side effects and does not rely on side effects from other code.

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 holds the statements that are to be executed when the function is called. The function body if a function created this way must always be wrapped in braces, even when it consists of only a single statement. Lastly, a function can have multiple parameters or no parameters at all.

  2. Bindings declared with let and const are in fact local to the block that they are declared in. Bindings using 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. 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?
    By defining a value and then binding it. A function is created with an expression that starts with the keyword function. A function can have multiple parameters or no parameters at all.

  2. What is the difference between var and let in regards to scope?
    Var has a global scope meaning it is visible throughout the whole program (if they are not in a function). Let only has a local scope meaning it can only be referenced within that particular function.

  3. What is a pure function?
    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 property where when called with the same arguments it always produces the same value.

1 Like
  1. by putting the keyword “function” in front of a value with parentheses, or => after the body of the value.
  2. Main difference is scoping rules. Variables declared by var keyword are scoped to the immediate function body (hence the function scope) while let variables are scoped to the immediate enclosing block denoted by { } (hence the block scope).
    c) a function that always produces the same result, no side effects.
1 Like
  1. How can you create a function in Javascript?

A function is created by calling “function” for example if i was going to create a function to carry out 1 + 2 I would write:

function addNumbers(){
var total = 1+2;
return total;
}

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

var can be defined in the global scope unless declared within the function, let is used in block scoping.

  1. What is a pure function?

a pure function is one that produces a result that is not impacted by other functions and doesn’t impact other functions.

1 Like