Functions - Reading Assignment

1)You can create a function by writing the key-word function or by writing a arrow after the parameters in the parenthesis.The body of the function must be always in brackets.
2)Let allows variable to be seen locally and var let the variable been seen globally.
3)Pure function is the function that produces a value by its input values and it is not producing any side effect.

Hello,

  1. const function(a, b){//what it does}

  2. let works locally inside a function or bracket, var defines the variable globally.

  3. A pure function is a kind of function that doesn’t rely of side effects of other code but also doesn’t produce side effects of its own.

best

  1. How can you create a function in Javascript?

A function is created in JavaScript by using the keyword function. Functions may incorporate parameters and statements. The function body is wrapped in braces.

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

Binding declared with let or const are objects that are only accessible within the body of the function where they are declared. They would be considered local objects.

A variable declared with a var is defined throughout the scope of the program.

  1. What is a pure function?

A pure function is a specific and well-defined function with no side effects and it doesn’t rely on side effects from other code. There are no outside variables involved.

  1. How can you create a function in Javascript?
    you can create a function in javaScript by starting with the keyword function, naming the function make sure name has a clear concept, then designing the code you want that function to execute.
    ex. Function nameOfFunction(parameters) {code designed}

  2. What is the difference between var and let in regards to scope?
    the difference between “var” and “let” in regards to scope is var is recognized on a global scale and let is limited to the block variable was declared in.

  3. What is a pure function? a pure function is a function that does not real global values that might change value producing, that have no side effect so they always produce the same value. pure functions will work in any context.

  1. function insertNameHere() {
    // function commands
    }

  2. var is global and is recognized in though the whole program. let is only recognized in the block of code it is written in. if used outside of the block or outside of the brackets if you will. it will not be recognized.

  3. A pure function is it’s own scope and is not influenced by outside variables or parameters. I works as predicted.

  1. With a function keyword. Function needs to have a name and instructions that are in between {} braces.
  2. While let can be only available inside the scope it’s declared, like in for loop, var can be accessed outside the loop.
  3. Pure functions are functions that accept an input and return a value without modifying any data outside its scope(Side Effects). Its output or return value must depend on the input/arguments and pure functions must return a value.

1.A function is created with an expression that starts with the key word “function” and giving it parameters () ,and body {}
2. let -local scope, recognized by the block in which is declared
var -global scope
3. the return value is determent only by its input value, no side effects to observe

1: By calling the keyword function, and name the function and add ().

2: The var statement is used to declare a variable in JavaScript. A variable declared with the var keyword is defined throughout the program.

The let statement is used to declare a local variable in TypeScript. It is similar to the var keyword, but it has some restriction in scoping in comparison of the var keyword. The let keyword can enhance our code readability and decreases the chance of programming error. A variable declared with the let keyword is limited to the block-scoped only.

3: Gives the same output as the input. Used to map something.

  1. How can you create a function in Javascript?
    The keyword function followed by parenthesis, with or without parameters. Use brackets to
    create a block that contains an expression. the expression value is determined by the
    parameters. Functions and blocks can used inside other functions and blocks and can see out
    side the scope of the block unless there is a binding of the same name, then it can only see
    within its own scope. Functions can also be used as values in a larger expression.
  2. What is the difference between var and let in regards to scope?
    Let sets the binding to the local scope and cannot be seen outside its scope. Var allows the binding to be seen outside its scope but only from within the scope of its function. If not inside a function, var bindings can be seen in the global scope
  3. What is a pure function?
    A pure function always gives the same output for a specific input.
  1. With the keyword, mane it and the ()

  2. Var is recognised through out the whole program, let is recognised within the block.

  3. Same output as input, no side effects.

  1. In JavaScript there are three methods to creating a function by using the " Function " keyword

    a) when used as an expression

       // Define v to hold a function value
          const v = function (a) {
           console.log ( a + 3);
           };
    

    b) when used as a statement, declaring a binding (example z ) as giving the function as its value

       // Declare z to be a function
         function z ( a, b) {
         return a + b + 3 ;
          }
    

and finally c} a short cut way to declaring a function by using the => ( arrow function)

         let h = a => a  * 3 ;
  1. JavaScript has Global and Local scoping. Each block when declaring its bindings and parameters by the " let " or " const " keywords are only visible within that same block ie local scope. That particular function block bindings cannot be accessed or " seen " by outside function blocks ( ie global ) unless the " var " keyword is used.

  2. Functions in JavaScript can do two things - a) return a value and/or b) result in a side-effect. A pure JavaScript function is defined as a function that does not result in a side effect or depend on a side effect to execute.

  1. How can you create a function in Javascript?
    A JavaScript function is created with an expression starting with the “function” keyword, followed by a “functionName”, followed by the parameters in parentheses “()”, followed by a set of instructions in brackets “{}”.

  2. What is the difference between var and let in regards to scope?
    The “let” keyword allows you to declare variables limited in scope to the block, statement, or expression on which it is used. The “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 observable side effects.

  1. by using the keyword function, then name, and then open/close parentheses containing the arguments to the function,
    then followed by open/close curly brackets
  2. let has local scope to the block and can not be seen outside of it.
    var has global scope to the block and outside of it as long as it’s not in the function itself.
  3. a function that doesn’t produce any side-effects and isn’t dependant on any side-effects from other code.
  1. A function is created with an expression that starts with the keyword Function. You can also begin a function as a statement or by using the arrow method =>.

  2. “let” & “const” are local to the block they are declared in. Var is visable throughout the whole function they are in or throughout the global scope if they are not in a function.

  3. A pure function:

  • Has no side effects
  • Doesn’t read global bindings
  • When called with the same arguments, always produces the same value.

1. How can you create a function in Javascript?

functionName (parameters){
//dosomething code here
return parameter;
}

functions does not need to return a parameter always.

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

let its a local scoped to the block that is declared in, while var use global scope.

3. What is a pure function?

its a function that does not produce a side effect nor rely on any other code side effect.

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

  2. Let bindings are only active in the block/scope in which the let binding is declared. Var bindings are active in the whole function or throughout the global scope, if they are not in a function.

  3. A pure function returns always the same value, independent from the argument input.

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

In order to create a function you must declare the function by using the function keyword, then name said function. The block of code that is specified by this function can be implemented as often as necessary.

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

Let can only be accessed by the line of code it’s referenced in. Whereas var can be accessed globally within the script.

  1. What is a pure function?

Pure functions are a value producing function that has zero side effects and is not effected by side effects. Pure functions always produce the same value when called using the same arguments within the block of code.

1 Like

i. How can you create a function in Javascript? A function is created with an expression that starts with the keyword ‘function’, has input parameters (or no parameters) enclosed by parentheses and separated by commas, a body which are the statements that may be executed enclosed in braces, and an optional return value.

ii.What is the difference between var and let in regards to scope? The difference is the scoping, var is scoped to the nearest function block and let is scoped to the nearest enclosing block, which can be smaller than a function block. But they are both global if not in a block.

iii. What is a pure function? A pure function is a deterministic function. This means when a same input is passed every time, the function will return same output. In mathematical terms it is nothing but a well-defined function. A pure function will have the following properties. 1) It depends only on its own arguments. 2) It won’t try to change variables out of its scope.

1 Like
  1. A function is created with an expression that starts wit the keyword, function. Functions have a set of parameters - a body - which contains the statements that are to be executed when the function is called. The function body is always wrapped in braces.

  2. In regards to scope, bindings declared with let is local to the block that they are declared. Var was used in pre-2015 JavaScript version and created with the var keyword, are visible throughout the entire function it appears - or are through in the global scope, if they are not a function.

  3. A pure function is a specific kind of value producing function that not only has no side effects but doesn’t rely on side effects from other code.

1 Like

1.A function is defined using the keyword function, followed by name, followed by parentheses containing the arguments of the function, followed by the body of the function with curved brackets/parenthesis

2.var and let are both used for variable declaration in javascript but the difference between them is that var is function scoped and let is block scoped. It can be said that a variable declared with var is defined throughout the program as compared to let . -https://www.geeksforgeeks.org/difference-between-var-and-let-in-javascript/

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

1 Like