Functions - Reading Assignment

  1. How can you create a function in Javascript?

Function is a variable which takes function as value.

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

let is a local binding while var is a global binding. Let cannot be used outside of the block which local binding it was created.While var is global and can be used anywhere.

  1. What is a pure function?

a pure function is a function which does not take into any global or local bindings as input. A pure function is also free of side effects.

2 Likes

1 How can you create a function in Javascript?
-function(parameters) {code to execute}
2What is the difference between var and let in regards to scope?
-let and const are local to the block that they are declared in and var bindings are visible to the whole function and declared global.
3 What is a pure function?
-Specific kind of value producing function with no side effects and relies on no side effects from other code.

2 Likes
  1. Function xyz(a) would be an example where you are setting what xyz is and what want to do with it.
  2. Let is essentially a short term hold of a variable, where as VAR will stay past just one block and hold its value until it is updated at some stage
  3. A pure function is one where the return value is purely calculated by the input values and by no other factors, should be no side effects observed
2 Likes

How can I create a function in JS : It starts with the keyword function and is given parameters § then it has a body containing a statement like { return p*p; } .

What is the difference between var and let in regards to scope : let is only active inside its own block (local use ) but var is active in the whole set of the program (global use).

What is a pure function : Function with the same argument === the same value and nothing else,

2 Likes
  1. You can either define is e.g. var x = function();
    Or
    Declare it e.g. function() {
    //body of function
    }

  2. var scope is global compared to let which is local and can only be seen within the block it is created.

  3. A function that returns the same value given the input and has no side effects.

2 Likes

1- A function is created with a keyword function() and then you give it an operation or statement with values to execute within {}.

2- A var value can be recognized outside of a block where let is used will be recognized only in the block.

3- Pure function is a function that does not have side effects and does not read global values.

1 Like
  1. name_of_function function(parameter “optional”){execution_statement};
const funkymode = function(a){return "pop'n bottles in the " + a;};
console.log(funkymode("club"));
// pop'n bottles in the club
  1. “var” bindings persist throughout the function, or at a global scope. “let” & “const” bindings exist only in the scope of the single action of the function (local), and if used in a loop, will only be seen within the loop.

  2. A function that doesn’t read global values, and doesn’t rely on or produce side effects.

1 Like

1)Function is created by using function keyword which is followed by parentheses() which contain parameters and it also have a body which contains statement that are to be executed when someone calls the function
2)Bindings created using let keyword is limited to block or statement while bindings created using var keyword defines variable globally.
3)A pure function is a function that has no side effects and it also doesn’t rely on side effects of other code

1 Like

1.by declaration or within a variable expression.
2.let will connect the variable only in the scope block and var connect to the global 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

2 Likes

1. How can you create a function in Javascript?
When you use the expression function, you are on a good way.
Simple said function() {your code goes here}

2. What is the difference between var and let in regards to scope?
let lives inside the function and var is used also outside your function

3. What is a pure function?
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)

1 Like
  1. How can you create a function in Javascript?
    A function is created with an expression that starts with the keyword function. By declaring function keyword followed by name when function is called, then arguments inside the parentheses and then function body wrapped in curly braces were you can write the function statements and outside the curly braces were you have to call the function name followed by parentheses and semicolon.

  2. What is the difference between var and let in regards to scope?
    Binding declared in let keyword is only visible in the local block. Binding keyword var however not only visible in local block but it is also visible throughout the global scope and could cause an issue with other block code.

  3. What is a pure function?
    Pure function is a specific kind of value producing function, it always produced same value when called with the same arguments. It doesn’t have a side effects.

1 Like
  1. How can you create a function in Javascript?
    const FuncionName = function(parameter list){function body}

  2. What is the difference between var and let in regards to scope?
    var is more global in scope, let is local.

  3. What is a pure function?
    A function that always produces the same result when called with the same parameters.

1 Like
  1. By using the function keyword. An expression contains a set of parameters and a body.
  2. A var can be used globally, while let is for a specific 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.
1 Like
  1. You can create a function expression ie. let myFunc = function(), you can declare a function ie. function myNum(), or an arrow function const myFunc = () =>
  2. let is block scoped while var can be used as a global scope regardless of block declaration.
  3. A put function performs one purpose, independently and will always give the same output when the same parameters are passed to it. It does not rely on global variables
1 Like
  1. How can you create a function in Javascript?
  • A function is created by starting an expression with keyword function in Javascript.
  1. What is the difference between var and let in regards to scope?
  • The difference between var and let in regards to scope is that var creates a “global” variable binding where outside blocks can see it as a variable where let creates a “local” variable binding inside of a block where outsiders would not see the variable.
  1. What is a pure function?
  • A pure function is a value producing function with no side effects and has no reliance on other code with side effects.
1 Like
function name(parameterA,parameterB){
code to be executed
}
  1. let allows you to declare variables that are limited to the scope of a block statement, or expression on which it is used, unlike the var keyword, which declares a variable globally, or locally to an entire function regardless of block scope

3.pure functions is function without side effects and always returns the same result :


1 Like

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 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?
Bindings declared with the keyword let are local to the block that they are declared in, so if created inside of a loop, the code before and after the loop cannot “see” it.

Bindings declared with the var keyword are defined globally, or locally to an entire function regardless of the block scope.

3. What is a pure function?
A pure function is a function that will - given the same input - always return the same output (value) and a pure function produces no side effects, which means that it can’t alter any external state.

2 Likes
  1. You can create a function in Javascript by using the function() syntax, the ‘=>’ syntax. A function needs to be identified with ‘const’ syntax, and can have any number of parameters or not.
  2. var has a more global scope and can be seen anywhere in the function. let is only visible in the block or environment in which it was written.
  3. A pure function has no side effects, does not rely on side effects from other functions, and only outputs a value. A pure function will always output the same value for a given input, in any context.
1 Like

Thanks Malik. That JS book tends to jump forward quite a bit sometimes with some of its examples in ways that would tend to throw off anyone who doesn’t have some familiarity with the concepts already.

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

By using the const function comand

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

Let is often limited to the local scope so within the function it is declared in while Var is used in the global environment and can be recognized by the entire program

  1. What is a pure function?

Is a function that has no nor requires any side effects and produces a specific kind of value

1 Like