Functions - Reading Assignment

  1. How can you create a function in Javascript?
    you can create a function in javascript by three ways.
    using a function key word,
    creating a binding that hold function as value
    using a arrow sign that also refer to function.

  2. What is the difference between var and let in regards to scope?
    Binding created with words Var are global in nature depending where they are being created. i.e if created within scoop of function they will be work as globally for that function environment.
    Binding created with words Let are local in nature they will be used in block they are created.

binding created with Let words have limited scoop and treated local to the environment where they are created.

  1. What is a pure function?
    Function that return value. It has no side effect and use no global bindings either.
  1. How can you create a function in Javascript?
    Using a function key word, creating a binding that hold function as value, using an arrow sign that allow to refer to function

  2. What is the difference between var and let in regards to scope?
    Let bindings are local and will be used only in the block they are created. Var bindings are global in nature and will end up in the nearest scope or global scope.

  3. What is a pure function?
    It is a function that returns only value. It also does not have any side effects and it does not rely on any outside (global) variables.

1 Like
  1. How can you create a function in Javascript?
    A function is created by using the key word function, adding a name and within parenthesis adding the parameter or parameters and within curly braces adding a body that will contain the statements or logic. No semicolon is needed at the end.

  2. What is the difference between var and let in regards to scope?
    var is a global binding and function scoped while let is a local binding and block scoped meaning that it cannot be seen by the code before or after it.

  3. What is a pure function?
    A pure function is a type of function that has to produces identical returns for identical arguments every single time and also it should not have any side effects.

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

You create a function with the keyword ‘function’, a set of parameters and a body.

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

Var is global in scope and let is local in scope.

  1. What is a pure function?

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. When called with the same arguments, it always produces the same value, and doesn’t do anything else.

1 Like

1. How can you create a function in Javascript?
Function is created with function (with multiply parameters or without parameter) {body}
2. What is the difference between var and let in regards to scope?
var global keyword, let local keyword. It means let keyword visible in the block and unvisible from outside, var is visible from outside the block also.

3. What is a pure function?
pure function gives the same result with same input with no side effects.

1 Like
  1. How can you create a function in Javascript?
    By using the keyword function in combination with some parameters and a body.
  2. What is the difference between var and let in regards to scope?
    Var is global while let is local so it cannot be seen by the code before and after it.
  3. What is a pure function?
    A pure function produces identical returns for identical arguments and has no side value.
1 Like
  1. How can you create a function in Javascript?

You can create a function in Javascript in three ways;

  1. By using function as an expression to create a function value

const multiple1 = function (a){
console.log (a * 2);
}

  1. By using function as a statement to declare a binding and give it a function as it’s value

function = total(a, b){
return a + b + 10;
}

  1. By using an Arrow function for a less verbose function value

let multi10 = a => a * 10

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

Let, when used inside a local scope, is only visible in that local scope; whereas var, when used inside a local scope, can also be seen in the global scope, unless var is used inside a function.

  1. What is a pure function?

A pure function has no side effects and relies solely on the code within the function.

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

To start, a JavaScript function is a block of code designed to perform a particular task. A JavaScript function is defined with the function keyword, followed by a name , followed by parentheses () .

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

In functions, arguments (code to be executed) behave as local variables. In reguards to scope, [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 reguardless of block.

  1. What is a pure function?

A pure function is a function that given the same input will always return the same output and it producess no side effects. They are completely independent of outside state, do not alter any external states, easy to move around and reuse throughout a program, and great for future adaptations.

1 Like
  1. Functions in JavaScript are created with the function keyword, followed by open and closed parenthesis with optional parameters inside. This is followed by open and closed brackets containing the body. The body contains statements that are executed when the function is called.
  2. In general, var has wider scope than let. Var is scoped throughout the whole function, while let is only scoped within the block where it belongs.
  3. Pure functions are functions whose output will always be the same when you give it the same inputs. These functions don’t rely on the state of bindings that have a larger scope than they have.
1 Like

How can you create a function in JavaScript?

  1. Use the keyword function followed by the name of the function .
  2. After the function name, open and close parentheses.
  3. After parenthesis, open and close curly braces.
  4. Within curly braces, write your lines of code.
    What is the difference between var and let in regards to scope?
    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 .
  5. What is a pure function?
    function is called pure function if it always returns the same result for same argument values and it has no side effects like modifying an argument (or global variable) or outputting something. … Examples of pure functions are strlen(), pow(), sqrt() etc.
1 Like
  • How can you create a function in Javascript?
    you make an expresion that starts with the keyword Function

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

var’s scope is through the global scope whereas let only has scope inside the function it has been created it.

  • What is a pure function?
    ???
    [/quote]

1 Starting the code with the keyword function, giving it a name, and a list of arguments in parenthesis. Then could bind assigning a variable, declaring itself, or using an arrow syntax.
2 Var refers to the function, is more limited, let refers to the whole block.
3 Pure because it is like math, gives always the same results, and is related only to itself, with no side effects.

1 Like
  1. How can you create a function in Javascript?
    Start with the keyword ‘function’, followed by parameters (in brackets) and a body containing the statement to be executed

  2. What is the difference between var and let in regards to scope?
    var is available across the whole function, but let is only local to the block bloc it is declared in.

  3. What is a pure function?

    Pure functions are functions that accept an input and returns 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 Like
  1. to call a function you will write the keyword “function” followed by a function name, a set of parenthesis, and curly brackets.

  2. Keyword “var” will define a global variable, while the keyword “let” will define a variable only to a specific statement, block, or expression.

  3. Prue functions return a value, with giving no observable side effects.

1 Like
  1. A function is created in Javascript by using the function keyword. Like the var and let keywords you need to give a name to the binding. For example, function toPrint (). the brackets indicate a value input. You don’t necessarily require a value in the brakets (i.e it can be empty) or you can put any number of variables in the brackets.

  2. The var keyword’s scope can fall outside the function block, so if you define a var outside of a function it can still be utilized within the function as long as they are near the function (nearest function). Let, however, does not act like this is can only be defined in the local environment (in the scope of the function) and all other let keywords that fall outside the local environment will be ignored.

  3. A pure function is one that has no side effects and does not rely on side effects from any other code. It will always return the same value for the same arguments regardless of when it is used within the context of the program.

1 Like

1. How can you create a function in JavaScript?
A function can be created in two ways;

  • By creating a binding with the keyword const, where the value is a function with set parameters in brackets followed by the function body with statement(s) to be executed.
//Here we see the makeNoise function has no parameters. 
const makeNoise = function() {
//The function requires no extra input, and once called will console.log Pling!
console.log("Pling!");
};
//When the function is called, brackets must be included regardless of parameters being present or not. . 
makeNoise();
// → Pling!
  • By beginning an expression with the keyword function, followed by the name of the function, parameters and the function body. This is a more succint approach and is called function declaration, which allow users to define the function later in the block as they get hoisted to the top of the scope.
function coolName () {
  return("Cool stuff printed to console as a string, sweet.")
};

coolName();
//→Cool stuff printed to console as a string, sweet.

2. What is the difference between var and let in terms of scope?
The keyword let (and const) create local bindings, which can only be referred to or called on within the ‘scope’ or range of the block in the function they are declared/defined in. (Local scope/Block scope)

They keyword var has a global scope, meaning that if it is declared inside a function, it can be referenced throughout the entire function, not only it’s origin block, and if it is declared outside a function it can be referenced throughout the whole code environment.

let x = 10;
if (true) {
    let y = 20; 
    var z = 30;
    console.log(x+y+z);
}
console.log(x);
//returns 10 as it was defined with let outside the function and each scope can 'look out' to neighboring scopes.
console.log(y);
// returns undefined as y is defined with let, within the if block of the function, and so it's scope or range is limited to that block only. 
console.log(z);
//returns 30, as although it is declared within a block, var has larger scope and allows it to be referenced throughout the function. 

3. What is a pure function?
A pure function is a value producing function which does not invoke any side effects, nor does it rely on the side effects of other pieces of code.

1 Like
  1. a function is created with an expression that starts with the key word “function”. Functions have a set of parameters and a body which contains the statements that are to be executed.
  2. Bindings created with “var” are global in scope. Bindings created with “let” are local and can only be used in the block were they have been assigned.
  3. A function that returns only value. It has no side effects and does not rely on outside variables.
1 Like
  1. Expression + keyword “function” + parameters() and a body, which gets executed
  2. var is function scoped, let is block scoped
  3. Fx that accept an input and returns a value without modifying any data outside its scope (side effects).
1 Like
  1. How can you create a function in Javascript?

A function is created with an expression that starts with a keyword function.
A function statement is hoisted at the top of the execution context, a function expression is not hoisted and can be created without a name, and an arrow function does not have its own this object.

  1. What is the difference between var and let in regards to scope?
    Both are keywords in JavaScript used to declare variables.

var uses function scope, var variables belong to the global scope when you define them outside a function.
When you declare a variable inside a function using the var keyword, the scope of the variable is local.

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

  1. What is a pure function?

A pure function is a function which: given the same input, will always return the same output and produces no side effects.

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

A function is created in JavaScript by creating an expression that starts with the keyword function. Functions have a set of parameters and a body.

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

Let is only visible within the scope of the block in which it was created. Var on the other hand is visible throughout the entire scope of the function in which it was created or throughout the global scope if they are not in a function.

3.	What is a pure function?   

A pure function is a function that accepts input and returns a value without modifying any data outside its scope. The output must depend on the input/ argument put into function. Pure functions must return a value.

1 Like