Functions - Reading Assignment

  1. How can you create a function in Javascript?

A function is created with an expression that starts with the keyword function. This is followed by a set of parameters and a body which contains the statement that are to be executed when the function is called.

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

The scope of var is global, whereas, the scope of let is local.

  1. What is a pure function?

Pure Function is a function (a block of code) that always returns the same result if the same arguments are passed. It does not depend on any state, or data change during a program’s execution rather it only depends on its input arguments.

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 allows you to declare variables that are limited in scope to the block, statement, or expression on which it is used. var keyword defines a variable globally, or locally to an entire function regardless of block scope.
    3… What is a pure function?
    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. How can you create a function in Javascript?
You can call a function by putting parentheses after an expression that produces a function value.

2. What is the difference between var and let in regards to scope?
‘Var’ is function scoped but ‘let’ is block scoped.

3. What is a pure function?
Pure Function is a function that always returns the same result if the same arguments are passed. A pure function also doesn’t produce any side effects.

1 Like
  1. nameofourfunction = function(x; y; z){how the function should work}
  2. let is more local (usually given value refers only inside function, or statement) than var which may appear outside of function too
  3. Pure function always produces the same value (with the same arguments) and has no side effect from other code
1 Like

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?
Bindings declared with let and const are in fact local to the block that they
are declared in
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.
What is a pure function?
A pure function will always return the same result as the given parameters

1 Like
  1. Using a keyword “function” before the statement of the function body.
    function example(x1, x3, x3) {
    return x1* x2* x3;
    }

  2. Let works locally and var can work locally (in the function) or globally

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

function happy(name) {
console.log(My name is ${name});
}
console.log(happy(“Mike”);

2.let bindings are local to the block that they are defined in and var are visible throughout the whole function.

3.A 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, followed by a name and parenteses ().

  2. What is the difference between var and let in regards to scope?
    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.

  3. 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. You can create a function in Javascript using the function keyword a few ways like this:
const cube = function(x) {
    return x * x * x;
};

function cube(x) {
    return x * x * x;
};
  1. Bindings declared with let are local to the block they are created in, so if you use let inside of a loop, that code before and after the loop can’t see that binding, but bindings created with var are visible to the entire function or the entire global scope if it was not created inside of a function.
  2. A pure function is a function that doesn’t produce any side effects or rely on the side effects of other code.
1 Like
  1. A function is created with an expression that starts with the word function, followed by parentheses “( )” containing perimeters, then by curly bracket “{ }” containing the statements that are to be executed.
    ex. Function name(parameters) {code to be executed}

  2. The difference between var and let in the regards of scope is that let creates a variable that is viewed/known only in the function, local, and can only be referenced within the function. In comparison var is viewed globally and can be referenced anywhere throughout, if written outside the function.

  3. A pure function is a function that if given the same input any number of times, it will always return the same output. No side effects are produced or relied on.

1 Like

-to create a function, you write its return type then its name then its parameters inside parenthesis and finally inside curly brackets, write a code that should run when you call that function.

let allows you to declare variables that are limited to the scope of a block statement , or expression on which it’s used
var keyword declare a variable globally, or locally to an entire function regardless of block scope

-pure function always return the same result if the same argument are passed . it does not depend on any state or date change during a prgram’s execution rather it only depents on it input arguments

1 Like

1. How can you create a function in JavaScript? A function is created with an expression that starts with the keyword ‘function’. From there parameters are defined (or not) and a body contains the statements to be executed when the function is called.

2. What is the difference between ‘var’ and ‘let’ in regards to scope? In JavaScript, the scope of ‘var’ is global and the scope of ‘let’ is local. While you can use either keyword to create a binding, ‘let’ is commonly found in loops and functions.

3. What is a “pure” function? This is a spefici kind of vaule-producing function that has no side-effects, and has no dependencies on outside global bindings. It always produces the same value when called with the same arguments.

1 Like

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?

var variables are available globally and let variables are only available within the block of code for a particular loop, they are local to the loop block only and are not available globally.

What is a pure function?

n pure function is a function that only returns values and not any side effects. It also does not read global bindings which values might change.

1 Like

function name = function (parameter 1,2,3) {instructions}

‘Let’ is local to the block that it is declared in and ‘Var’ is global and visible to the whole function (if they are not in a function).

A pure function doesn’t rely on side effects from other code and has no side effects. It performs the same function and produces the same value regardless of global bindings.

1 Like
  1. You can create a function in javascript by creating a function value through the use of the statement “function” followed by a name. After that you place parentheses to add potential argument(s).
  2. The scope determines in which part of the program a certain binding is visible. Bindings created with let are only visible in the block in which they are created. Thats why they are called local bindings. Bindings created with var are visible in a whole function or program.
  3. Pure functions are functions that has no side effects in itself or other codes. It produces a value and produces always the same.
1 Like
  1. A function is created with an expression that begins with the word function, followed by a name and then (). Functions may have parameters or not. The function will have a body which contains statements that are to be executed when the function is called.
  2. var is visible throughout the entire function. let is local, so the code before and after does not recognize the function.
  3. A pure function does not have side effects it only relies on the input values
1 Like
  1. How can you create a function in Javascript?

A function is created with an expression that starts with the keyword function (=> arrow functions can also be used to create a function). It consist of a set of parameters and a body that contains the statements. However functions do not follow the same top-to-bottom control flow. Functions can be declared below the code that uses it.

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

Let bindings scope extends only to the block that it was declared in. Var if inside a function goes throughout the whole function and if outside a function, it will have a global scope of the entire code once it has been declared.

  1. What is a pure function?

A pure function is a value-producing function that has no side effects and doesn’t rely on side effects from other code. A pure function when called with the same arguments will produce the same value.

1 Like
  1. You can create a function with the function keyword, or with the arrow, =>
  2. The difference between var and let in scope is that let is local to a specific block, while a var can be global in scope.
  3. A pure function is one that returns the same result irrespective of state, as long as the same arguments are made.
1 Like
  1. Functions are created by writing keywords that create a functional value. These are executed by calling, declaring or defining keywords. Functions execute at proper conditions such as “while” loop; execute once then at proper conditions such as “do-while” loop; iterate through all object properties and multiple items as in “for-in” loop; “if else” statements and by behavior changing (continue and break statements). Syntax and document object model (DOM) are relevant to functions.
  2. Bindings and scopes are integral in that each binding has a scope. A scope that is local has keywords such as “let” that is limited only to that function, assigned only to that function. The functions before and after the let function does not see or respond to it.
    Whereas, “var” is somewhat more complex than “let.” Var is deemed “global” and is recognized throughout the code and in the whole function.
  3. A pure function is void of mixture with and of other coded side effects and changeable values; does not rely on side effects or other code. When called with the same argument, it produces the same value every time and nothing else. Interestingly, a pure function can be tested by substituting it’s return value without changing the meaning of the code.
1 Like
  1. By using the keyword function you start creating one. A function has a body which contains the statement to be executed & a set of parameters.These parameters can be empty or carry more than one value.
  2. The difference between let an var bindings is that let bindings are local to the block they’re in. Var bindings are visible throughout the whole function or the global scope if they are not part of a function
  3. A pure function returns only a value but no side effects. Also it doesn’t rely on side effects from other codes.
1 Like