Functions - Reading Assignment

  1. a function is created with the keyword function followed by the parameters (in parenthesis) followed by the body in {curly brackets}.
  2. let is only a local function, the rest of the program doesn’t see it. var can be used inside a function the same as let or used outside a function to be seen globally.
  3. A pure function doesn’t produce any side effects and doesn’t need side effects from other code.
1 Like

1.) If you write the word function. There are different ways If you want to write an function of a square.
Like this: const square = function (x){return xx;}. or like this: function square(x){return xx;}
2.) Var is a binding that scopes global. Let is a binding that scopes local.
3.) A pure function has no site effects and doesnt read global bindings. When its called with the same Arguments it always produces the same Value.

1 Like
  1. You create a function in JavaScript by using the keyword function followed by a set of parameters that are defined within the body.

  2. The difference between var & let in regards to scope is as follows:
    var = the old style binding where as the binding can been seen throughout the whole function (global)
    let = is a (local) binding that is not able to be seen before or after the loop in which it is contained.

  3. A pure function is a function that when given an input will always produce the same output with no side effects.

1 Like
  1. You can create a function in java like this
function NFT () 2. Var mean global , Let mean Local 3.a Input that makes the same output each time code is executed with no side effect.
2 Likes

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 (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.
A function can have multiple parameters or no parameters at all.

What is the difference between var and let in regards to scope?
let - when created insides of a loop, the code before and after the loop cannot “see” it.
var - are visible throughout the whole function that they appear in—or throughout the global scope, if they are not in a function.

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.

2 Likes
  1. A function is created with an expression that starts with the keyword function -> function()
  2. let keyword defines a variable that is limited to the scope, statement or expression of the block. var keyword defines a variable globally or localy to the entire function regadless of the block. In ES6 (ES2015) they added these two keyword var and const which create block-scoped variables, while var creates function - scped variable.
  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. Same Input => Same Output (without side effects).
2 Likes

A.1. A function in JacaScript can be created with an expression that starts with the keyword function. Function expressions store variables and have a set of parameters and or arguments. Parameters are the names listed in the function definition. Arguments are the real values passed to (and received by) the function.

A.2. In regards to scope the difference between var and let are as follows:
var—is a biding keyword with a global scope. It is visible throughout the whole function whereas let—is a biding keyword local to the block it is declared in.

A.3. A pure function simply takes an Input and produces an Output. This means when a same Input is passed every time, the function will return same Output. Input is also known as “argument” and Output is also known as “return value”.

1 Like

1). A function is defined using the keyword function, followed by name, followed by parentheses containing the arguments of the function; then, the body of the function with curly brackets.

2). Let is local bindings and only usable in the block they are declared in. Var is global binding and globally used.

  1. A pure function is a type of function when called with the same arguments, it always produces the same value.
2 Likes
  • How can you create a function in Javascript?
    By: A function as a statement, expression, arrow function, using the function instructor

  • What is the difference between var and let in regards to scope?
    The main difference between let and var is that scope of a variable defined with let is limited to the block in which it is declared while variable declared with var has the global scope. So we can say that var is rather a keyword which defines a variable globally regardless of block scope.

  • What is a pure function?
    A pure function is a deterministic function . This means when the same input is passed every time, the function will return the same output. In mathematical terms, it is nothing but a ** well-defined function.**

2 Likes
  1. How can you create a function in JavaScript?

There are different ways to create a function:

Define a function to hold a specific value (function definition). This can be done either with a regular function definition or with an arrow function. Both variations yield the same result, but the arrow function can be written in a more concise way.

Declare a variable to be a function (function declaration).

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

“let” can be used to create both global and local variables. When used inside a block (e.g. regular block, loop block, if-clause), “let” creates a variable with a scope limited to the block it was created in. When used outside a block, “let” creates a global variable. “var” on the other side, creates always a variable with a global scope, irrespective of whether the variable was created inside or outside a block. However, the scope of a variable defined within a function block is always local, even when the keyword “var” is used.

  1. What is a pure function?

A pure function always creates the same output given the same parameters. It does not create any side effects and does not affect anything outside of its function boundaries. A pure function is also not affected by any side effect of the rest of the program.

2 Likes
  1. How can you create a function in Javascript?
    A function can be created as an expression using the let (or var) and function keywords or as a statement using a function declaration.

let triple = function(x) {
return 3 * x;
};

function triple(x) {
return 3 * x;
}

  1. What is the difference between var and let in regards to scope?
    A var is always given function scope even if declared in a block, where let is given block scope.

  2. What is a pure function?
    A pure function is a deterministic function meaning that provided the same inputs it will always produce the same result. A pure function depends only on its own argument and won’t use arguments outside its scope. Additionally, a pure function doesn’t produce any side effects.

2 Likes
  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.
  2. What is the difference between var and let in regards to scope?
    Variables are regarded global, which essentially means they can be used by any part of the code. “Let” is used for more local purposes so the same names can be used in different contexts without the risk of overwriting its value for all the differents contexts (or scopes).
  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.
2 Likes
  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 function body must always be wrapped in braces.
  2. Bindings declared with let and const are in fact local to the block that they are declared in and bindings declared with var are visible throughout the whole function or throughout the global scope.
  3. A pure function is a specific kind of value-producing function that has no side effects and also doesn’t rely on side effects from other code.
1 Like
  1. You can create a function in Javascript with an expression that starts with the keyword “function” ,or using the function keyword as a statement or using “arrow” notation to write a function.

  2. var declaration is global, while let only works locally within the function from which it is declared.

  3. A pure function is a function in which an input will always produce the exact same result output. A pure function produces no side effects(a function that doesn’t return any side effects and does not rely on side effects from other code).

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 followed by 2 brackets. The first bracket () contains a set of parameters, but not necessarily. The second bracket {} contains the body, which contains statements that are to be executed when the function is called.

  2. What is the difference between var and let in regards to scope?
    Let has a local effect. If let is created inside a loop, the code before and after the loop cannot see it.
    On the other hand, var can be seen throughout the global scope

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

2.“Var” keyword defines a variable globally to an entire function. “Let” allows you to declare variables that are limited in scope to the block, statement, or expression on which it is used.

3.A pure function is a function where the return value is only determined by input values, without observable side effects.

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

  2. Let is in fact local to the block that they are declared in, Var can be visible through out the whole function or throughout the global scope.

  3. 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. Functions in JavaScript are created by wrapping a piece of program in a value so it can be reused and called multiple times. This is done with an expression that starts with the keyword function followed by the parameters and body of the function.
  2. The difference between var and let is that var is visible globally if it is outside of a function where as let and const are visible locally.
  3. A pure function is value producing function that has no side effects and also does not rely on any side effects from other code.
1 Like

var x = myFunction(1, 2); // 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
}

  1. A Var is function scoped and Let is block scoped

  2. A pure function is a function that always returns the same result

1 Like

@ivan
I Have a question, can you explain this concept and code to me line by line. what’s happening on return line of the function. is multiplier function is returning a function? if so what is this number thing who is multiplying with factor parameter? what is this closure concept… ?

function multiplier(factor) { return number => number * factor;}
let twice = multiplier(2); console.log(twice(5));
// → 10