Functions - Reading Assignment

  1. How can you create a function in Javascript?

One way is o declare itwith the function keyword.

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

Let are global bindings, while var are local bindings.

  1. What is a pure function?

A function without side effects.

1 Like
  1. By using the function keyword. You can give the function parameters and a body. The parameters are bindings that are to be defined when the function is called. The body contains the statements that will be executed when the function is called.

  2. Bindings declared with let and const can only be seen within the block they are declared in. Bindings declared with var can be seen by all code within the function.

  3. A pure function has no side effects and does not rely on side effects from other code.

1 Like
  1. A function is created with the function keywork, followed by the name, followed by parentheses.

  2. Let - declares a variable limited to the block, statement, or expression on which it is being used.
    Var - defines a variable globally

  3. A function that given the same input will always return the same output. It also produces no side effects.

1 Like
  1. With the keyword function , then we need to set the parameters and the body of the function, which will be executed when the function is called.

  2. Bindings such as let and const are local to the block they are declared in, and bindings created with var are vsible throughout the function they are declared 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

Functions created by an Expression with a Keyword, with/without parameters and a body.
Var-globally Let locally
Input=Output no side effects

1 Like
  1. How can you create a function in Javascript?
    Using the keyword function (setting parameters) and {the body of instructions to execute}

  2. What is the difference between var and let in regards to scope?
    Let is local to the block being called (not visible outside of the block) whereas var is global (seen throughout the whole function).

  3. What is a pure function?
    A specific value producing function has no side effects and does not rely on side effects from other code. When called with the same arguments - always produces the same value (and only that).

1 Like
  1. A function can be created by an expression with keyword “function” in the front and a body of statements for execution wrapped in braces.

  2. Var has global scope, so it is visible throughout the whole program; While let has local scope, so it is visible only within the function it is declared in.

  3. A pure function refers to a function that produces values only, produces no side effects nor relies on side effects from other codes.

1 Like

1. How can you create a function in Javascript?
A function is created by starting an expression with the word: function

2. What is the difference between var and let in regards to scope?
Var: Sets a global parameter for the value of the whole program.
Let: Sets a local parameter for the value of the block.

3. What is a pure function?
A block of code that always returns the same result if the same arguments are passed.

1 Like
  1. How can you create a function in Javascript?
    To create a function in Javascipt one has to write an expression that starts with the keyword function. Then define the set of parameters and a body that contains the statements that are to be executed when calling on the function. To further expand, the function body of a function must be wrapped in braces.

  2. What is the difference between var and let in regards to scope?
    The difference between var and let in regards to scope is that var is defined throughout the program and is global compared to let that is a locally binding to the block that they are declared in.

  3. What is a pure function?
    A pure function is a kind of value-producing function that has both no side effects but also doesn’t rely on side effects from other code. When called with the same agreements, it always produces the same value. Calls to pure functions can be substituted by its return value without changing the meaning of the code.

1 Like
  1. How can you create a function in Javascript?
    Input passes through a function to produce an output.
    a). Use the keyword function followed by the name of the function.
    b). After the function name, open and close parentheses.
    c). After parenthesis, open and close curly braces.
    d). Within curly braces, write your lines of code.
    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. Parameters to a function behave like regular bindings, but their initial values are given by the caller of the function, not the code in the function itself.
  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. This is unlike the var keyword, which defines a variable globally, or locally to an entire function regardless of block scope.
  3. What is a pure function?
    A pure function given the same input, it returns the same output and produces no side effects.
    [/quote]
1 Like

Reading Assignment: Functions

  1. How can you create a function in Javascript?
  • By using the keyword function, (), and {}
  • It can have a name and parameters, though not required
  • It can return a value, side affect, or both
  1. What is the difference between var and let in regards to scope?
  • let has the context of scope in which it was declared and not beyond
  • var has the ability to be accessed outside of the bounds of scope of where it was declared
  1. What is a pure function?
  • A pure function returns a value that can be determined the output no matter the inputs, such as (return num * num) which will return the square of that number entered as opposed to a number that generates a random number or a varied output, even if the same number is entered as an argument or used. The code itself generates varying results.
1 Like

1.Invoke a fuction using the word function(x){} with the instructions inside of the brackets and the parameters in the parenthesis.
2. A function can create exclusively local bindings, meaning, the variables in the function are only affected inside of it and not globally.
3. A pure function, given the same variables, always produces the same result. A pure function is not affected by global bindings.

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

A function is created with an expression that starts with the keyword function and has a set of parameters, and a body that has the statements that are execuited when the function is called.

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

The scope of var is global, or the whole program (you can refer to it wherever you want in the program. The scope of let is local, or only the function or block that they are declared in.

  1. 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. With an expression that starts with keyword function and then followed by a set of parameters and a body that holds the statement that will be executed when the function is called.

  2. Var is global, let is local (not seen outside the function).

  3. It is a special value producing function that has no side effects and doesn’t rely on any other side effects from the code.

1 Like
  1. How can you create a function in Javascript?
    By defining a function using the keyword function with the associated parameters and expression of the function you wish to create.

  2. What is the difference between var and let in regards to scope?
    Var is older and had a global declaration of the variable beyond the local environment of the function for which it was declared
    Let is local and defines the variable within the block it is being used as it is in a function

  3. What is a pure function?
    One which neither produces nor is affected by side effects, nor is affected by any global state of variables. It fairly isolated and produces the same output for a given input every time because of these properties.

1 Like
  1. const square = function(x) {
    return x * x;
    };
    console.log(square(12));
    // → 144

  2. var is global
    let is local

  3. when there are no side effects

1 Like

Questions:
. The key word function is placed in a line of code followed by brackets: function(){
console.log();
};.
. Let variables exist only in the local binding with limited scope while var variables exist throughout the whole function as they have a wider scope.
. Pure functions return values without any side effects.

1 Like

//Defining x to hold a function value:
const x = function (y, z){
return(y + z);}
//Shorter way of the version above:
const x = (y,z) => { return y + z;}
//Declaring x to be a function:
function x(y, z){
return(y + z);}
2. Bindings with let and const are local to the block that they are declared in, while bindings with var are visible throughout the whole function that they appear in or throughout the global scope, if the are not in a function.
3. Pure function is a function that doesnt have any side effects and doesnt rely on side effects from other code.

1 Like
  1. Use the function keyword to start a function, followed the appropriate parameters.
  2. var is global and let is local
  3. A pure function will always produce the same results, dependent on its variables of course. It’s not affected by global bindings.
1 Like
  1. By writting an expression that starts with the keyword function, adding its set of parameters, and then its body.

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