Functions - Reading Assignment

1- Just like a regular binding which is a variable to a value, in this case the function is our value binded.

2- var is a global binding, yet let is a local binding. When global bindings are created, you can refer to such bindings wherever you want. Local bindings declared inside a function can be referenced only in that 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. A function is created with an expression that starts with the keyword function, setting parameters for the functions abilities, and creating a body (wrapped within {}) to contain the statements that are to be executed when the function is called; functions are able to have many or no parameters.
  2. var keywords are scoped to the immediate function body of a program, while the let keyword is enclosed to the immediate block within a functions abilities.
  3. 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; it will not read global bindings whose value might change.
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 parameters (in this case, only x ) 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?
    var is a global binding keyword while Let is a local binding keyword. Global Bindings can refer to anything they want whenever they want. while local bindings are more enclosed and can only be referenced inside a function.

  3. What is a pure function?
    is a specific kind of value-producing function that has no side effects and won’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 starting with the key word function.

  2. What is the difference between var and let in regards to scope?
    The difference is that let allows you to declare variables that are limited to the scope of a block statement whereas var declares a variable globally, or locally to an entire function regardless of block scope.

  3. What is a pure function?
    A pure function is a function which does not depend on and does not modify the state of variables out of scope. This means that a pure function always returns the same result given the same parameters. Its execution does not depend on the state of the system.

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

You can create a function by creating an expression with the keyword function. The function has a set of parameters and a body that contains statements.

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

Bindings declared with let are local bindings, meaning that when used within a block they do not see the code used before or after it. However, bindings declared with var are visible to the entire function they’re in or throughout the global scope.

  1. What is a pure function?

A pure function produces a value that has no side effects and doesn’t rely on side effects from other code. Meaning that if the value for a global binding changes, it will not affect the pure function.

1 Like
  1. create expression with keyword “function” with a set of parameters and a body

  2. var - keyword seen globally by all functions in program
    let/const - keyword recognized only in local block

  3. input / return a value without modifying any data outside its scope( no side effects)

1 Like
  1. To create a function you must first start with the keyword: function, this lets JavaScript know that you’re about to make a function. After telling JS you’re making a function you must come up with a expression for it. This can be a almost any word of your choice.
    For example. function MyFunction
    Followed by two parameters that will let you set what your function will have for value, or string.

Function myFunction( “Hello”) {
document.write(myFunction + “” + “My darling”)
}
Outcome: Hello My darling

  1. The difference between var and let.
    var stands for variable, it is used when you want to declare a value to a variable or your choice.
    Let’s say: var a = 2
    For JS this means that all a’s in the code will have the value 2.

let is a little bit different, it only lets you declare a variable inside a certain scope only, and will not be true for the rest of the code. They serve the same purpose for declaring a value though.

  1. A pure function doesn’t have any side effects, meaning when called with the same arguments it will always produce the same result.
1 Like
  1. const nameoffuction = fonction() { //code } ;

2 . ‘var’ is a variable that is set within a grobal scope and can be refer wherever we want in the program.
as for ‘let’ if set within a function will be only visible locally and only viable within the function itself if refer to.

  1. A pure function is a function that return an output without side effect and dosnt rely on other code or global bindings.
1 Like

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};

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

A binding declared with let is local to the block it is declared in. A binding declared with var is visible throughout the whole function or throughout the global scope, if it is not in a function.

What is a pure function?

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 property where when called with the same arguments it always produces the same value.

1 Like
  1. By designing a keyword function, or =>, to a (or more) parameters and a set of statements to be execute whenever the function is called.

Functions are composed of a binding, a keyword (or =>) and the parameters (which we call the body of the function).

  1. Bindings can be local (if declared inside a function) or global (if declared outside of any function).

When using the keyword Let (and const) we are creating a binding inside the block. But when we use the keyword Var the binding it produces reach the nearest function scope or the global scope.

  1. Its a function that doesn’t need variables that tend to chance along the code. It produces no side effects and doesn’t read global bindings.
1 Like
  1. use the keyword function then create a name for your function, followed by (), that’s one way. It depends on the type of function you will be using. Most common functions are Name Functions like the one below:
    function testExample(you can put parameters in here, or leave it empty) {instructions to be executed};
    call the function
    ------are you confused?

First of all I stopped using the book because it is not useful for me. It doesn’t explain anything.
I recommend Dani Krossing on youtube

  1. There are different types of scope (block scope, function scope… to name a few) let and var have different effects for block scopes and function scopes, whether they are local (in the scope) or global (outside the scope)

Function Scopes:
var: declared outside a function scope can be used inside and outside the scope
var: declared inside a function scope can only be used inside the scope, not outside the scope
let: declared outside a function scope can be used inside and outside the scope
let: declared inside a function scope can only be used inside the scope, not outside the scope

Block Scopes: if, for, while
var: declared outside or inside a block scope can be used inside and outside the scope
let: declared outside a function scope can be used inside and outside the scope
let: declared inside a function scope can only be used inside the scope, not outside the scope

  1. no side effects an outputs are always the same, and not affected by other code in the program.
1 Like
  1. There are 3 popular ways to create a function in Javascript.

    • The first is by declaring a function as a value. This is done by binding the function to a value, as follows:
      let functionName = function(arg1, arg2) {functionBody;};
    • The second is by using declaration notation, where a semicolon ( ; ) is not required after the braces of the function body. A function can be created using declaring notation as follows:
      function functionName(arg1, arg2) {functionBody;}
    • The third and more recently established method is the arrow is by declaring an arrow function. This is where the programmer can format a function for example:
      const functionName = (arg1, arg2) => {functionBody;};
  2. Declaring a binding using var will allow the variable to always be called on a global scope. This means that from any format of nesting from expressions across the program, the var variable will be called in the state it was declared here.
    The a let variable is declared within a function, this is known as local scope. Variables which have binding on a local scope using a let declaration can be used only in the function in which it is declared. So if a variable is declared inside a function using let, and further down the program, another function wishes to use this variable, it will take the characteristic of undefined as it’s scope is exclusively bound to the context of the function it was called in.

  3. A pure function is a function which does not create any side effects, or rely on side effects to produce a result. This means it is the purest form of arithmetic, and it can be used across the program, substituting values where the context requires. The benefit of pure functions means that it is highly versatile and flexible to several contexts. An example of a pure function could be something as simple as:
    const addNums = (num1, num2) = > {return num1 + num2;};
    So if the programmer at any point wishes to add two numbers, they can enter:
    addNums(4, 8); and the program will print 12. The two arguments here could also be any number or variable.

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 parameters and a body that contains the statements that are executed when the function is called.

  2. What is the difference between var and let in regards to scope?
    Bindings declared with let are local to the block they are declared in. In pre-2015 JavaScript, var bindings were visible throughout the whole function that they appear in, or through the global scope if they are not in a function.

  3. What is a pure function?
    A pure function always produces the same value when called with the same arguments, and can be substituted with its return value without changing the meaning of the code. Doesn’t produce side effects. It is not influenced by global variables.

1 Like

1 - there’s 3 different ways that you can create a function in java…

const square = function(y) { return y * y; }

function square(x) { return x*x; }

let square = x => x*x;

2 - let binding have only local scope. Let binding declared within a curly brakets only have scope within those brakets and not outside. var binding have scope outside of curly brakets. var scope is only limited if it’s inside of a function. That is, a var binding declared inside of a function cannot be called from outside of the function.

3 - a pure function is a function that is self contained and with no side effects. It does not interact with variable or values outside of the function.

1 Like
  1. How can you create a function in Javascript? You can declare it by using the function keyword at the beginning of the statement or define it by storing the function as the value of a binding:

Function declaration:

function square(x) {
return x * x;
}

Function definition:

const square = function(x) {
return x * x;
};
  1. What is the difference between var and let in regards to scope? let creates a variable only visible from the block they’ve been created in (for loop, if statement…) which will not be accessible from outside that block whereas var creates a variable that is accessible from the whole function (if it has been created in a function) or from the whole program (if it has been created outside a function).

  2. 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. A pure function has the pleasant property that, when called with the same arguments, it always produces the same value.

1 Like
  1. How can you create a function in Javascript?
  • Use the keyword function followed by the name of the function.
  • After the function name, open and close parentheses.
  • After parenthesis, open and close curly braces.
  • Within curly braces, write your lines of code.
  1. What is the difference between var and let in regards to scope?
    The scope of a variable defined with let is limited to the block in which it is declared. However, var has the global scope.

  2. What is a pure function?
    A 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. You create a function by the keyword function(){stuff;}
  2. The difference between var and let is the fact that let is local to block, and not seen later on, compared to var which is global.
  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 A function is create using: Keyword function, followed by parameters inside parentheses, followed by the function body in curly braces

2 Bindings declared with let and const are local to the block that they are declared in. Var bindings are visible throughout the whole function that they appear in

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. How can you create a function in Javascript?

const nameOfFunction = (function(e.g. number, number));

OR

function functionName () {
// code inside};*

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

var is a global variable, let is local

  1. What is a pure function?

A function that only relies on on its own variables (arguments) instead of global ones. Produces no side effects.

1 Like

1.- A function can be created by defining a variable “X” - These have purpose on resulting in a value.
2.- Let is local to the block that they declared in, if you create a loop (Only that loop can see it but the ones before and after cannot) - Var can be seen throughout the global scope.
3.- It is a function that will always bring back the same value not depending on any binding.

1 Like