Functions - Reading Assignment

  1. By writing the word function and then entering in what you want it to do in the curly brackets.
  2. Var is a variable with a global scope whereas let retains the scope locally.
  3. A pure function will always produce the same value. It doesn’t produce side effects or rely on them. This is beneficial because if you test it once you know it will work the same throughout the program.
1 Like

1, Start with an identifier const then give it a name, put an expression ( = operator), keyword function followed by a set of parameter in parentheses ( ) and that followed by a body in brackets *{ }*which contain the statement that are about to be executed
const name = function(parameter){body ; } ;

2, let is local to the block while var ends up in the nearest function or the global scope

3, Given the same input will always return the same output with no side effects.
e.g function priceAfterTax(productPrice){return(product*0,2)+productPrice;}

1 Like

1.) function functionname (parameters) {code to execute}
2.) Let and const are local to the block that they are declared to. Var binding are visible in the whole function they are declared in or global if they aren’t in any function.
3.) Pure code is a function that doesn’t rely on side effects and doesn’t have 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 body of a function 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.

    • let keyword 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. A pure function is a function where the return value is only determined by its input values, without observable side effects.

1 Like
  1. ***How can you create a function in Javascript?
    Functions are created with an expression that starts with the keyword function. They have a set of parameters and a body which contains a statement(s) that will be executed when the function is called upon. The function body must be wrapped in braces.
  2. ***What is the difference between var and let in regards to scope?
    “var” can be seen global, this is by the whole program, whereas “let” is local meaning it cannot be seen outside of the block.
  3. ***What is a pure function?
    This is a function that has no side-effects and which does not rely on side-effects from other code either.
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.

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

with the keyword “function”, a set of parameters and a body which are the statements to be executed when the function is called. the body function should be in braces even though it has a single statement. after the body, comes the return statement.

the var keyword are visible through the whole function, would appear in the global scope while let keyword are in local scope to the block they are declared in.

A pure function has consistency between arguments and outputs. Same arguments would always return same output. Has no side-effects.
It’s a pure function only if the same argument produces the same output value.

1 Like
  1. using keyword function(parameters){
    perform function
    return value
    }

  2. Let is local to block, function, environment, etc
    var is global

  3. A pure function only returns a value, no side effects

1 Like
  1. How can you create a function in Javascript?
    By creating an expression that begins with the keyword function . It is built with a set of parameters in parentheses, and a body wrapped in braces which contain the statement that is to be executed when the function is called. A return statement determines how the function returns. If it simply has a side effect and not a return statement, it will return undefined.

  2. What is the difference between var and let in regards to scope?
    let is local in scope, can only be seen within the the block in which they are declared
    var is “global” in scope, can be called upon all throughout the program

  3. What is a pure function?
    A pure function always produces the same value when called with the same arguments. It does not read global bindings nor rely on side effects from other code

1 Like
  1. A function is created with an expression that starts with teh keyword function.
    2.the difference is that let is local in the block,so the code before and after cannot see it and var is visible throughout the global scope.
    3.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.
1 Like
  1. To create a function you use the keyword function followed by the name of the function, then the parameters, and then the body of the function in brackets.
    2 The difference in var and let is that let is used for local scopes, and not the global scope. Var is used outside of the local blocks for a global usage.
  2. A pure function is one that has the same return value structure without changing because of the code processing.
1 Like

How can you create a function in Javascript?
to create a function you can use var Name= function(arguments){function}; or declare it like function Name (arguments){function};

  • What is the difference between var and let in regards to scope?
    var has a global scope as let only in the block it is located…

  • What is a pure function?
    A pure funcition is a function that always produces the same value, doesnt depend from outside variables
    [/quote]

1 Like
  1. functions can be created as a value of a variable, using the function keyword, or using the => operator
  2. var scope is limited to the function body. let scope is limited to the block
  3. A pure function is an idempotent function with no side effects.
1 Like
  1. How can you create a function in Javascript? A function is created with the keyword “function” followed by the name of the function in parenthesis ( ) and, then, followed by the action to be executed in braces{ }.

2 What is the difference between var and let in regards to scope? Var allows for values that are global with regard to the program - whereas let defines values that are specific to a local block of code.

  1. What is a pure function? A pure function yields a specific value related to specific input with no side effects.
1 Like
  1. There are several methods:
    - const f= function(parameters) {
    body
    }
    - function name() {
    }
    - const a=(b,c) => b*c;

  2. let allows you to declare a variable that is limited to the block in which it is contained.
    var allows you to declare a variable that is valid for the whole program.

  3. It is a function that does not produce side effects. The same input produces the same output. It can be replaced directly by writing the result it gives, because it is always the same.

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

Function as value of a binding
const functionName = function(param1, param2) {
action of function;
};

or function declaration

function functionName(param1, param2) {
action of function;
}
(Note: no semi colon needed at the end)

or use an arrow function =>

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

let has a local scope (it will only be visible inside a function) and var has a global scope

  • What is a pure function?

A pure function is a function which always produces the same output given the same input, it has no side effects and does not read global bindings

2 Likes

1.A function is created by calling a “function”, followed by a set of parameters(), containing statements that are executed. In the function, you can have parameters that are empty or parameters used in the function. Functions can either produce value or a side effect.
2. The let variable is local to the block it is called in, var is universal and can be called at any point in the sequence. Let must be in the function.
3. A specific kind of value-producing function that has no involvement with 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 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?

let is recognized by the block in which the variable is declare. var is dif by all
the program

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. Function is an expression created with the code function, function may or may not have a set of parameters in it.

  2. var is function scoped and let is block scoped.

  3. Pure functions are functions that accept an input and returns a value without modifying any data outside its scope.

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

A function is invoked by writing the keyword function, followed by an expression.

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

The scope of let is local, meaning it is only “remembered” within its block, while the scope of var is global, meaning it is “remembered” throughout the entire program.

  1. What is a pure function?

A pure function only produces a value, but not a side effect, and is also not affected by other side effects present in the environment. A call to a pure function could, therefore, always be substituted with its return value.

1 Like