Functions - Reading Assignment

  • How can you create a function in Javascript?
    = A function is created with an expression that starts with the keyword function.

  • What is the difference between var and let in regards to scope?
    = let scope doesn’t exist outside of the block and var scope exists in the global environment.

  • What is a pure function?
    = A pure function is a function that doesn’t have any side-effects and doesn’t rely on side-effects from other code. It has the property that it always produces the same value if the same inputs are passed.

1 Like

1: One way to create a function is the => and this tells the computer that is a function.
2: let is limited in scope for the variables you want to use only for that block or function. var keyword defines the variable on a global level and will continue even after the functions are executed.
3: A pure function is a value-producing function that has no side effects and doesn’t affect any other piece of code.

1 Like
  1. function functionName(parameters) {code to execute}
  2. var is accessible throughout the code(global) while let is limited to the code block(local).
  3. Pure function is a function that has no side effects in its output.
1 Like
  1. A function in Javascript starts with the keyword “function,” then ( ).
  2. Let is local to the block and var is visible throughout the whole function or global if it’s not in a function.
  3. A pure function does not have any side effects and does not use other side effects from other code, pure function(s) also produce the same values.
1 Like

1 The function consists of the function keyword, followed by the name, parentheses, parameters, curly braces, and the code to be executed.

2 Let is a variable limited by the block only, var variable can be global.

3 A pure function always returns the same result with the same input parameters.

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

Three ways - define a variable to hold a function value:

const f = function(a) {
console.log(a + 2);
};

Declare a function directly with the function keyword:

function test(a){
return a + 2;
}

Or define a function value in a more concise way added in 2015:

let test2 = a => a + 2;

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

Bindings are local to the scope they are declared in and not visible outside that scope, except for those made with var which are either global or end up in the nearest function scope.

  1. What is a pure function?

A value-producing function with no side-effects and that doesn’t rely on side-effects from other code. It will always produce the same results when provided the same arguments.

1 Like
  1. How can you create a function in Javascript?
    This is done by using the key word “function” followed by brackets ()
    function(){…}

  2. What is the difference between var and let in regards to scope?
    var is visible to the whole function they appear in or throughout the global scope.

let keyword mean local to the block it is declared in.

  1. What is a pure function?
    This is a function that does not rely on the result of another function.
1 Like

1- first assigning a name to that function , the a regular binding, where the value of the value is the function.
2- let is used for the local scope of the block, while var is more for the global scope of the function.
3- It is a function in which its value is determined by its inputs, with no side effects.

  1. A function is created with an expression that starts with the keyword function.
  2. Bindings declared with let are local to the block they are declared in. Bindings declared with var 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
  1. How can you create a function in Javascript?
    Functions are one of the fundamental building blocks inJavaScript. A
    function is a reusable set of statements toperform a task or calculate a value. Functions can bepassed one or more values and can return a value atthe end of their execution. In order to use a function,you must define it somewhere in the scope where you want to call it.

  2. What is the difference between var and let in regards to scope?
    Words with a special meaning, such as let, are keywords, and they may not be used as binding names. A single let statement may define multiple bindings.
    Bindings declared with var behave differently—they end up in the nearest function scope or the global scope.

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

  • name of the function
  • parameters - inside the parentheses
  • body of the function - consist of statements to be executed when is the function called, is inside of curly braces
    2.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.
    3.A pure function is one that produces no side effects nor does it depend from side effects from other functions. It works as a standalone and will always produce the same results if called with the same arguments.
1 Like
  1. A function is created with an expression that starts with the keyword function, the body of a
    function created this way must always be wrapped in braces

2.A function definition is a regular binding where the value of the binding is a function.
Each binding has a scope, which is the part of the program in which the binding is visible.
For bindings defined outside of any function or block, the scope is the whole program: global bindings
Bindings created for function parameters or declared inside a function: local bindings
Bindings declared with let and const are in fact local to the block that they are declared in
Bindings created with the var keyword : global bindings

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

How can you create a function in Javascript?
We can create functions in many different ways :slight_smile: but simplifying, a function is a set of operations wrapped up in curvy brackets with a return value at the end. We will then bind this set of operations with a name (before the curly brackets) and define between brackets what will be the number of inputs (if any) between the brackets in front of the name. Example below

var example (a, b, c, … ) {
//set of operations
return x; }

What is the difference between var and let in regards to scope?
When we define a variable, string, function with VAR it will be read all across the program - these are called global variables. With LET it will be only readable inside the block of code it is inserted in.

What is a pure function?
A pure function it’s a piece of code that doesn’t have side effects, nor it relies on outside side effects from other piece of code. Of course it will always need input arguments, but the difference from other functions is that a so called pure function will always have the same input-output.

1 Like
  1. How can you create a function in Javascript?
    By using the word “function”+ “(parameter)”+"{body}"

  2. What is the difference between var and let in regards to scope?
    Var-scope continues its existince outside a block, let scope only keep inside blocks

  3. What is a pure function?
    Producing function that has no side effects and does not rely on side effects from other code.

1 Like
  1. A function is a process which takes some input, called arguments , and produces some output called a return value. A function is created with the expression that starts with the keyword function. It has a set of parameters - e.g, ( use this, b) and a body - which contains the statements that are to be executed when the function is called. The function body must be wrapped by braces.

  2. A binding declared with “var” keyword is a global binding. The binding declared with “let, or const” is a local binding in the scope of the function itself and not in the scope of the entire program containing all functions. Binding with keyword “var” is within the scope of the entire program.

  3. A pure function provides referential transparency. Given the same input, will always return the same output. It produces no side effects: It does not save the value to a disk or logging to the console. Pure functions take same input and return same output based on that input. Pure functions are studpid simple in the best possible way.

1 Like
  1. const greeting = function(){console.log(“Hello!”)
  2. var = global, let = local
  3. Function with no side effects and also doesn’t rely on side effects from other code.
1 Like
  1. By writing function, giving it a name and putting down paratheses with or without parameters, and using curly braces to give the function its body

  2. Var has scope within the immediate function and let only has scope within enclosing block {}

  3. It is a function that works independently from what is happening in the code, it is context-independent. It also has no side effects on the rest of the code

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

a) By defining a binding using the keyword “function”, followed by brackets, which can contain arguments or not, and then giving the function a block of code that is executed when the function is called.

const square = function(num) {
return num * num;
};
square(3);
9

b) By using a function declaration:

function square(num) {
return num * num;
}
square(3);
9

  1. What is the difference between var and let in regards to scope?
    “var” has global scope (i.e. - seen throughout code, even within defined blocks, whereas “let” has local scope (i.e. - seen within local block only)

  2. What is a pure function?
    A pure function returns only an expected value and no side effects, and returns the same expected value on every occurrence, when the same argument(s) is/are presented.

1 Like
  1. How can you create a function in Javascript? function name (a) {return } -->f(x)
    =y
  2. What is the difference between var and let in regards to scope? var decalres a variable , let eclares a variable limited to the block, statement, or expression on which it is used.
  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—for
    example, it doesn’t read global bindings whose value might change.
1 Like
  1. How can you create a function in Javascript?
    You create a function by giving an expression a fixed task.
    ex. function name(){
    };

  2. What is the difference between var and let in regards to scope?
    Var is a function scope and let is a block scoped, let is limited to it’s block while var can be used outside with certain arguments

  3. What is a pure function?
    Has no side effects giving it the same input will always return the same input.

1 Like