Functions - Reading Assignment

  1. How can you create a function in Javascript?
    To declare with a variable and make it equal to a function.
    Ex. const func = function() { //code inside };
    To write function then the name after it.
    Ex. function func() { //code inside};
  2. 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.
  3. What is a pure function?
    It doesn’t produce or rely on side effects, avoids reading global bindings.
1 Like

1. How can you create a function in Javascript?
You can call the keyword function and assign parameter input. Inside the body you will define how the parameters will be used in statements to define function output.
2. What is the difference between var and let in regards to scope?
var can be called out globally whereas let can be called out locally to the block within the function.
3. What is a pure function?
It is a function that does not have side effects, but does not rely on side effects from other code. When parameters are input to a pure function it will always provide the same output.

2 Likes
  1. How can you create a function in Javascript?
    to create a function we use the keyword “function” followed by its name the parentheses where parameters can go separated by commas.
  2. What is the difference between var and let in regards to scope?
    “var” is defined by the program following its declaration while “let” variables are scoped to the immediate enclosing block denoted by " { } "
  3. What is a pure function?
    A pure function is a function that always returns the same result if the same arguments are passed in.
2 Likes
  1. You can create a function in Javascript by the expression that starts with a keyword “function.” You then follow the keyword “function” with a label of your own, followed by parameters “().” inside of these parameters are what’s called the “arguments,” which are inputs of value that are run through the “body” of the function -> the meat and bones of what the function actually does. “Return” will be the value/side effect of the executed function, coded at the end of the body.

  2. The difference between “var” and “let” is minuscule, basically doing the same thing. However, in regards to scoping, var is used for the global code, called upon whenever “var” was last given a value (or for the entire function it is used inside of). “Let,” on the other hand, is used locally, within the confines of the created function/inner function. Outside of this function/inner function, the value given to “let” is not used, more so ignored, by the computer reading the code.

  3. Pure functions must have identical returns for identical arguments, along with having no side effects. They don’t alter anything outside of the function, they have no correlation to anything time related and are not dependent on fluctuating outside values.

1 Like
  1. a function can be created by declaring a variable and assigning it to a function such as
    var const = function(x, y);
  2. Declaring a “let” variable inside of a loop is not visible to the rest of the function, whereas creating a “var” variable can be seen throughout the whole of the code.
  3. a “pure function” is a type of function that produces a value independently of the rest of the code
2 Likes

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

Both “var” and “let” are used to define variables, but “var” is used to define global variables (they can be seen along all the program) and “let” is used to define local variables (they can only be seen inside the function or sub functions where they are located).

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). 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). A call to such a function can be substituted by its return value without changing the meaning of the code.

3 Likes
  1. You can create a function by using .function
  2. Let is local only, var is global if not in a function.
  3. A pure function returns no side effects and returns the same values for the same arguments.
2 Likes

Great answers. It’s easy to understand. Great work. :clap:

Carlos Z.

2 Likes
  1. Examples for functions:
const square1 = function(x) {
   return x * x;
};

function square2(x) {
   return x * x;
}
  1. Defining a variable by using the “let” keyword is using local scope. It is part of JavaScript since ECMAScript 6. “var” uses global scope or the scope of the current function.

  2. 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. 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.- You start with a keyword and then you assign a function to it, similar to how a variable works.
2.- Var defines a variable globally and let is relative to the statement it is used in.
3.- A function that will give the same output if given the same input, and has no side effects.

1 Like
  1. You can create a function in Javascript by:

i) Using a regular binding to hold a function value, like in “const a = function (x) {function body}”
ii) Declaring it in a statement, like in “function b(x) {function body}”
iii) As an arrow function, with simplified syntax “const c = (x) => {function body}”

  1. Bindings declared with “let” and “const” are local to the block that they are declared in, while bindings declared with “var” are global, recognizable in the whole program (with some exceptions);

  2. A pure function is a function that produces a value, has no side effects, and doesn’t rely on side effects from other parts of the code. It is a function that, when called with the same arguments, always produces the same value.

2 Likes

How can you create a function in Javascript?
There are three ways of creating a function in JS.

First you can make a reference to it by defining a variable to hold on to a function
value

const myFunction = function(x, y) {
code 
};

Second you can declare a function by itself with a function name

function myFunction(x, y) {
code
}

Third you can use the arrow function for a shorter variant.

What is the difference between var and let in regards to scope?
Var can have a global scope or a local function scope, let can have those scopes but also get other local scoping as in loops or if statements.

What is a pure function?
A pure function is a function where the function is not reliant on side effects from the function or other external codes. A pure function has a clear return value to its caller.

1 Like
  1. setting a const equal to function() and then defining what function() does
  2. Bindings described with var can be seen by the whole code while let and const can’t be.
  3. given the same input will always produce the same output, with no side effects.
2 Likes
  1. How can you create a function in Javascript? A function is created when you name the function and then follow it by parentheses. Parameters go within the parenthesis. Here’s an example:
function area(l,w) {
return l * w;
}

Functions can also be written as statements:

const b = function(q) {
  console.log(q * 3);
  1. What is the difference between var and let in regard to scope?
    Bindings created with var are visible throughout the whole function, while bindings declared with let are local to the block that they are created in.

  2. What is a pure function?
    A pure function is a specific kind of value-producing function that does not rely on side effects from other code, produces no side effects itself, and always produces the same value. It is generally simple, and doesn’t do anything else.

1 Like

Functions - Reading Assignment.

  1. Functions - is created by using an expression that starts with a keyword of function. Using with/without parameters and the body that contains the statement to be executed.

  2. The difference between the var and let in regard to scope is, while let can be only available inside the scope it’s declared, var can be assessed outside the loop. It has 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 codes. It has the property that when called with the same arguments, it always produces the same value (and doesn’t do anything else).

1 Like
  1. A function is created with an expression that starts with the keyword function
  • function can have multiple or no parameters (x, y)
    const square = function(x){
    return x * x;
    };
    console.log(square(12))
    //144

  • another way to write a function ex: // declare g to be a function
    function g(a, b){
    return a - b
    }

2.parameters / bindings declared in a given scope with const and let are local to the block and cant be seen outside the block
Bindings declared with “var” behave differently, they end up in the nearest function scope, or the global scope

  1. a pure function is a specific kind of value producing function that not only has no side effects, but also doesnt rely on the side effects from other code.
  • doesnt read global bindings that might change

  • when called with the same arguments it produces the same value

1 Like
  1. A function is created with an expression that starts with the keyword function. Some
    functions have parameters and some don’t.
  2. Let is limited to a block and cannot be seen outside of it, while Var defines a variable
    with a larger scope, local within a function or global.
  3. A pure function is a function that will always return the same output as long as the same
    input is inserted and they do not produce side effects.
1 Like
  1. How can you create a function in Javascript?
    A function is created by using the function() piece of code. .This is bound to a variable and can have no parameters or multiple. A function can also be called using the arrow (=>) assignment. A function can be called upon to perform a specific task. A function is used to create an output based on the input given.

  2. What is the difference between var and let in regards to scope?
    var is a global binding which means that once it is assigned it can be used globally across the code. The let binding can only be “seen” by the code in that specific block. If a let binding is attempted to be called from a different block of code then it won’t be “seen” and able to be used.

  3. What is a pure function?
    A pure function is one that has no side effects. A pure function will always give the same output for the same input with no additional effects occuring.

1 Like
  1. A function is created with an expression that starts with the keyword function and open closed parenthesis
    function()

  2. let is a local binding, created for function parameters or declared inside a function that can be
    referenced only in that function

  3. A purefunction 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. How can you create a function in Javascript?
    A function is created with an expression that starts with the keyword “function”.
  2. What is the difference between var and let in regards to scope?
    let declares a variable limited to the block in use. var defines a variable globally.
    3.What is a pure function?
    It is a function that doesn’t produce side effects and also it doesn’t rely on side effects from other code.
1 Like