Functions - Reading Assignment

How can you create a function in Javascript?
A function is created with an expression that starts with the keyword function.
With or without a set of parameters.

What is the difference between var and let in regards to scope?
let and const use block scoping, they won’t appear locally. Var uses the
global scope if they are not declared 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

1 Like
  1. A function is created by using an expression that starts with the keyword function. Functions have parameters and a body that contains statements to be executed.

  2. Let is used locally to the block that they are declared in. Var is used globally. Meaning that the variable can be used throughout the program.

  3. A pure function is a function that produces a value that doesn’t have any side effects or doesn’t rely on any side effects.

1 Like
  1. function funtionName (Var1, Var2, …) {set of instructions}

  2. let allows the declaration of variables that limited to the block, statement, or expression it is exemplified in. var is a keyword that defines can define a variable globally, locally, or to an entire function.

  3. A pure function is a function where the return value is only defined by its input values.

1 Like
  1. How can you create a function in Javascript?
    The function keyword starts declaring a function. Example:
    function addTwoNumbers(x, y) {
    return x + y;
    } // function name is addTwoNumbers, x,y are the functions parameters , returns the sum of x + y
  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. 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 is a function which: Given the same input, will always return the same output. Produces no side effects.
1 Like
  1. A function can be created with the function keyword or symbol, a parameter between parenthesis, and a body. It has a binding which works exactly like in variables

  2. “var” is the keyword to create a binding which has a global scope and can be seen by the entire environment while “let” is for local scope only and can only be seen by the loop where they are.

3)A pure function is a function that doesn’t create or is not affected by side effects.

1 Like

1.With keyword - function, when used as an expression with given parameter and body.
2. var is global binding (inside and outside the loop). let is local when it’s created in the loop.
3. It’s 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.

1 Like

1.Function keyword and curly braces, function() { };
2. var keyword defines a variable globally, or locally to an entire function regardless of block scope.
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

1 Like
  1. with the keyword, function
  2. let; is a local binding to the function only. it does not reference binding beyond the function that calls it. var; will access the value in the global scope weather they are within the function or not.
  3. 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. How can you create a function in Javascript? It starts with an expression that has a keyword
    “function” and has a set of parameters () and a body which has a statement that executes when the function is called the function created must be wrapped in curly braces even if it only has a single statement .
  2. What is the difference between var and let in regards to scope? The difference is that “var” has a global environment, where" let" is a local environment when it is wrapped in a function.
    so if created inside a loop it becomes local. outside it becomes global.
  3. What is a pure function? This has a specific kind of value that has no side effects, it doesn’t rely on side effect from other code, it has a local environment and doesn’t read global.
1 Like
  1. How can you create a function in Javascript?

By using the keyword function, then optionally introducing parameters in the parentheses after the keyword and then writing the code which the function will execute wrapped in braces.

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

The keyword var defines a binding that has a global scope, while the binding defined by let has a local scope.

  1. What is a pure function?

A value-producing function that has no side effects and doesn’t not depend on side effects from other code. When called with the same arguments, it will always produce the same value.

1 Like
  1. By using function keyword, defining a name for the function, and defining any arguments. Example:
    const power = function(x, y){
    return x * y
    }

  2. Declaring a var binding inside a function will make that binding visible outside the function. Declaring a let binding inside a function will only be visible inside the function, but not outside. Declaring a let binding outside a function will be visible to all functions.

  3. A pure function is a function that is general-purpose and can be fit to many tasks. It is used for producing a return value that can be called anywhere, rather than a side effect limited to the context it was written for.

1 Like

1.Functions are created as a variable assignment with the keyword “function”, its parameters and the code it will execute to return a value:

Function definition:
let a = functionName(parameters){code to define return value or action to perform}

Calling the function:
funtionName(parameters)

  1. var is global while let is local to its block

  2. Pure functions are the ones that have no side effects, don’t rely on side effects from other code and when called with the same arguments always produce the same value.

1 Like
  1. A function is the concept of wrapping a piece of code into a value. A function is created with an expression that starts with the keyword “function”.

  2. Bindings, ie. var, const, let, have a scope in which the binding is visible to the program. var & const are global and always seen by the program. Where as let is local and seen during a function or block of the program.

  3. A pure function has a specific value producing return that is determined and repeatable by its inputs with no observable side effects.

1 Like
  1. A function is created with an expression that starts with the keyword function.
  2. Bindings declared with let are local to the block that they are declared in. 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.
1 Like

You can create a function in 3 ways:

  1. const a = function(b) { return b }
  2. function a(b) { return b }
  3. const a = b => b

2- var is accessable in the whole block, let is only accessable inside that scope

3- 1. 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. How can you create a function in Javascript?

A function is created starting the line with the word: function, the name we want to call the function, a set of parameters between parenthesis followed by a set of instructions. Ex:

function a ( b, c ) {

return b+ c;

}

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

a variable is set and it is the same for the all program, let will have fix value only inside the function

  1. What is a pure function?

a pure function is a function without side effects and not relying on any binding or other side effects.

1 Like
  1. A JavaScript function is defined with the function keyword, followed by a name , followed by parentheses () .strong text

  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 function that not only has no side effects, but it also doesn’t rely on side effects from other code.
    When it is called with the same arguments, it will always return the same result.

1 Like

Reading Assignments: Functions

1.A JavaScript function is defined with the function keyword, followed by a name, followed by parentheses (). Function names can contain letters, digits, underscores, and dollar signs (same rules as variables). The parentheses may include parameter names separated by commas: (parameter1, parameter2, …)
2.The main difference is the scope difference, while let can be only available inside the scope it’s declared, like in for loop, var can be accessed outside the loop for example. … This is unlike the var keyword, which defines a variable globally, or locally to an entire function regardless of block scope.

3.A pure function is a function which: Given the same input, will always return the same output. Produces no side effects.

1 Like
  1. A Function is created with an expression that starts with the keyword “function”. It has a set of parameters and a body which contains the statements that are to be executed if the function is called wrapped in braces.

  2. "Let"s scope is local to the block, “var” is visible globally throughout the entire function.

  3. A pure function is where the same input will return the same output without any side effects.

1 Like

This is 1000th comment rofl.

  1. How can you create a function in Javascript?

Function is created with a keyword “function”, its parameters (values) and body (what is executed when function is called, for example with keyword “return”).

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

If “let” is defined in a block (for example function) it is valid only for this block (its local scope) and code around this block can’t see it. Let is local.

If “var” is defined in a block (for example function) it is valid for the block (local scope) as well as for the outside of the block (global scope). Var is global.

  1. What is a pure function?

Pure function is a function that does not rely on any other global piece of code. It is sufficient with the values we enter into this pure function and it always returns the same output if inputs are the same. Pure function does not have a side effect.

1 Like