Functions - Reading Assignment


#182
  1. How can you create a function in Javascript?
    Functions can be created by using a binding (var, let, const) and the keyword function. Alternatively a function can be created by an expression that begins with the keyword function. Functions may take any number of parameters.
    e.g.

    function divideByTwo (x) {
    return x / 2;
    }
    divideByTwo (8)
    // -> 4

  2. What is the difference between var and let in regards to scope?
    If a function is named with the var binding then it has a global scope, if a function is named with let then its scope is localized.

  3. What is a pure function?
    A pure function is one that returns a value without creating side effects and without being dependent on side effects. Irrespective of the environment, pure functions return the same value when given the same parameters.


#183
  1. A function is created in JavaScript by creating an expression that starts with the keyword function. A function body must all be wrapped in braces.

  2. Var is a global binding. Let is a local binding. A global bindings scope is the whole program. Local bindings are bindings created for function parameters.

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


#184
  1. A Function in JavaScript is the beginning of the coding process. It can be defined as a block of code that performs an action or returns a value. Whether the coding program is long or short, simple or complex it will begin with a function. The text book Eloquent JavaScript says that "Functions are the bread and butter of Java Scrip programming".

  2. Scope in JavaScript determines how bindings are recognized in the programming. There are two types of scope: global and local . Bindings are defined as being in local scope when inside a function and in global scope when outside of a function. Var, as an old-style binding, is unique in that it is visible throughout the whole function where it is contained but becomes global if not in a function. Let and const bindings are local to the block wherein they are declared.

  3. A Pure Function is a predictable function in the code. Unlike a Non-pureFunction* its output does not depend on something else. The Pure Function produces only one output and is not required to change anything with its output. Consequently no computation is required in order to produce the same remembered value. It is a predictable function.


#185
  1. We can use (const f = function(arguments) {code}; or function g(arguments) {code};
  2. The scope of the let is only one block. Var has a scope of entire function or global
  3. It’s a function that producess value but has no side effects and relies on no side effects from the rest of the code

#186
  1. You first define the function with the keyword function, followed by a name and parameters within parentheses.
  2. var can define a variable globally or locally to an entire function regardless of block. let only defines a variable locally to the block, statement or expression that it is used on.
  3. A pure function is a function that if given the same input, returns the same output with no side effects.

#187

What Ekene04 said is the most concise response…


#188

1. How can you create a function in Javascript?

It is a regular binding where the value of the binding is a function. For example, this code defines square to refer to a function that produces the square of a given number:

const square = function(x) {

return x * x;

};

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

Bindings declared with let and const are local to the block that they are declared in, while bindings created with the var keyword, are global.

3. What is a pure function?

A function that 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.


#189
  1. const “name” = function(“parameters”) {
    function body
    return “something”;
    };

or

function “name”(“parameters”) {
function body
return “something”;
}

  1. let/const variable will only be available within the function, var variable will be available outside of the 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


#190

1. How can you create a function in Javascript?

A function can be defined in 3 different ways. The most common would be:

function add (num1, num2) {
return result = num1 + num2;
}

Called:

  console.log(add(3, 4));

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

Var is a function scope variable and let is a code block scope variable. Var can continue to contain a value after a block of code as long as it is in the same or higher level function that it is defined. Care should be taken using var as a global variable as it is then attached to the window object. The can be bad as 3rd party library could overwrite your variable.

3. What is a pure function?

A pure function only returns a value, it has no side effects of its own and does not use side effects from elsewhere. It does not use and global binding, therefore, it does not rely on outside code in any way.


#191
  1. A function is created with a with an expression that starts with the keyword function.
  2. let declares a variable limited to the block, statement, or expression on which it is used.
    var, on the other hand, defines a variable globally, or locally to an entire function regardless of the block.
  3. A pure function is a function that given the same input will always return the same output and it produces no side effects.

#192
  1. How can you create a function in Javascript?
    function fuctionName (parameters) {
    statement
    }

  2. What is the difference between var and let in regards to scope?
    var can be “seen” by global scope.
    let is not visible to the global scope, so it can be executed only in local enviroment.
    example:
    var x = 10;
    if (true) {
    let y = 20;
    var z = 30;
    console.log(x + y + z);
    }
    console.log(x + y + z);
    //60
    //Uncaught ReferenceError: y is not defined
    //y is not visible globaly (let variable name)

  3. What is a pure function?
    Pure function produces same value, independent of changes in code, thus same arguments procuces same value.
    Does not produces side effects.


#193

Functions can be reused as many times as you want with different arguments to produce different results.
It can be produced by following syntaxes

Syntax:1

function name (parameter1, parameter2, parameter3){
code to be executed
}

Where

function -Keyword

name : Name of the function;

Syntax:2(As we define variables)*

var a = function (parameters){

code to be executed

}

2.Let is recognized by the block/brackets in which the variable is declared i.e. local variable. var is recognised by all program i.e. global variable

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


#194

1, function functionName(outputs, arguments) {
body code
}
2, var can be global, let allows you to declare variable that are local to block, statement or ecpression.
3, Pure functions is one that always performs the same no matter the environment as all it’s variables are local to it!


#195
  1. How can you create a function in javascript?

You create a function by putting a binding to that value but the value of the binding itself is the function. You call the function and create parameters in its brackets then create the body which calls the function to be executed with the statements called.

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

Var is available on the global level of the code - where all other code can see it but let is local to a function. Let cannot be seen outside of where it is put.

Lexical scoping - Each local scope and can see all of the scopes that contain it, and all scopes can see the global scope.

  1. What is a pure function?

A pure function is one that has no side effects and uses no variables or bindings from the global scope. It does not take any other info code than it’s own and when given it’s arguments it will produce the same value each time.

Recursive - A function that calls itself

Argument - a value given to a function

Closure - a function that references bindings from local scopes


#196

How can you create a function in Javascript?
Function is created with an expression that starts with the keyword “function” and then you define what you want it to do “your variable” = Function( what) { how}

What is the difference between var and let in regards to scope?
Let is local, it isn’t a permanent grab, exists only for the time you needit and you can reuse the variables. var is global and if you try to declare two variables with the same name your console will tell you that that value has already been taken. var is permanent.

What is 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 code.


#197
  1. A JavaScript function is a block of code designed to perform a particular task.

A JavaScript function is executed when “something” invokes it (calls it). (source: w3schools.com)

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

  2. Pure function returns always the same result if the same arguments are imputed. It does not get modified by any other commands except the one that defines it


#198

Hello dear Community,

my answers to the questions are:

  1. How can you create a function in Javascript?

There are several ways to create functions.


A) via the “const”- and “function”-keyword:
const myFunc = function() {…};


B) via the “let”- and “function”-keyword:
let myFunc = function() {…};


C) only via the “function”-keyword:
function myFunc() {…} // n “;” needed
D) only via “const”-keyword:’
const myFunc = (argument1) => {return argument1*arguement1};
const myFunc = argument1 => argument1 * argument1; // the same as above

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

So, once a new value is assigned to a"var"-variable within a new scope, it will be overwritten even after the scope and not change it’s value again to the initial. A “let”-variable will remain the same even used in a scope where it will get temporally a new value assigned. If the loop is finished, the “let”-variable has the value from before the loop started.

  1. What is a pure function?

A function that is not related to changing variables.

Cheers
OtenMoten


#199
  1. How can you create a function in Javascript?
    We can create function by binding a program to a keyword we name ourselves.

  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?
    İts a function which is deterministic and has no side effects.
    Deterministic function: the function gives the same result everytime as long as the input is the same.


#200
  1. How can you create a function in Javascript?

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

  3. What is a pure function?

  4. You use a keyword function and add a parameter into the body of funcion

  5. let = can be seen scope to the block
    var= clobal scope not in the funtion

3.Pure funtions produces a value


#201
  1. To create a function, use const to create a constant binding of your function name, followed by the expression for the function, following this format:
    const functionName = function(parameter1,parameter2,...){
    // function formula or action, with or without return statement;
    };
    Note that you can take no parameter, and just give a side effect.

There are 2 other ways to create a function binding:

  • Declaration notation, where the above could look like:
    function functionName(parameter1,parameter2,...){
    // function formula or action, with or without return statement;
    }
    (note the absence of semi colon at the closing)
  • Arrow functions
    const functionName = (parameter1,parameter2,...) => {
    // function formula or action, with or without return statement;
    };
  1. let, if created inside of a loop, is local to it, and couldn’t be seen by code outside that loop, such as before or after that loop, even if it’s inside a function. var binding on the other hand, could be seen within the whole function, not just inside the loop it is created. And if outside the function, could be seen globally.

  2. A pure function is a specific kind of value-producing function that doesn’t have a side effect and doesn’t rely on side effects from other code. If called with the same arguments, it always produces the same value.