Functions - Reading Assignment

  • How can you create a function in Javascript?
    A function is created with an expression that starts with the keyword function and a body, which contains the statements that are to be executed when the function is called
  • What is the difference between var and let in regards to scope?
    Let is used when you want that value to be scoped only for the current block, we use
    var when we want it to be scoped outside the block
  • What is a pure function?
    A pure function is one that nor has or relies on other side effects.
2 Likes
  1. How can you create a function in Javascript?
    with an expression that starts with the keyword function

  2. What is the difference between var and let in regards to scope?
    let = declaratevariables in fact local to the block that they
    are declared in.
    Var=variable global

  3. What is a pure function?
    With pure funtion is a value producing function without side effects

1 Like
  1. Declare a function using the keyword function followed by a user defined name example
    function example(){
    }

  2. let is local to the block it is contained in.
    var is global

  3. A pure function is a value producing function that neither relies on side-effects or produces side-effects.

1 Like
  1. Use key word Function
    const ? = Function(?) {
  2. In regards to scope, let limits variable access to the scope of the block, and var allows a variable to be global and accessed outside the block.
  3. A true function is a function that does not produce a side effect.
1 Like
  1. const square = function(a) {
    return a * a;
    };

  2. let is only used in the local block while var is used throughout the entire program.

  3. specific value producing function that has no side effects, and doesn’t rely on side effects from other code.

1 Like
  1. How can you create a function in Javascript? just a binding with a funciton const square = funciton(x) { return x * x;};
  2. What is the difference between var and let in regards to scope? var is global let is local
  3. What is a pure function? no side effects and also doesn’t rely on side effects
1 Like
  1. With the “function” keyword + the name of the function + arguments + code
  2. “let” applies to a specific block and “var” can be used globally (outside of that block)
  3. A function that produces a value and does not create any side effects but also doesn´t rely on side effects from other code (or variables).
1 Like
  1. A function is created by declaring: function(parameter) {body}, by adding a veriable that equals to the function: const functionName = function(parameter) {body}, we can create different functions under different names.
  2. var is used through out the control flow, while the let will be used in ‘part of the code’ and will not be able to used in other sections of the code, for example: loop counters. after the loop ends we cannot call out the loop counter variable.
  3. A pure function is a non side effect function that doesn’t relay on other functions in the code and will always produce the same value output with the same input parameter.
1 Like

How can you create a function in Javascript?

with the function keyword

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

Bindings declared with let are in fact local to the block that they are declared in, the code before and after the loop cannot “see” it

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 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 need to use keyword “function”
  2. “let” and “const” are bindings local to the block. “var” binding is visible throughout the global scope
  3. A function that has no side effects and it does not rely on side effects from other code.
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?

1- * A function has 3 sections: its starts with the keyword function followed by parentheses within which parameters are usually passed - the last section is called the body which contains the statements that are executed when the function is called - the body is wrapped within braces . Parameters’ values are defined by the person calling the function:

function FunctionName (parameter1, parameter 2, parameter 3… ) {

the body aka the code to be executed;

}

2- *The difference between let and var: var defines a binding that is used throughout a program while a binding expressed by let is only defined locally within a block of code

3- A pure function is a function which returns the same value for the same argument without side effects

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

You create a function by defining the parameter and body of an expression as the value of a binding.

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

Let defineds keywords that are only visible to the function block they are apart of. Var keywords can be global if outside of a function or visible to entire block of function they are a part of.

  • What is a pure function?

Pure functions don’t produce side effects or use side effects from other functions, they are purpose driven to create a consistent value from arguments.

1 Like
  1. Functions can be created with an expression that starts with the keyword function e.g. const myNewFunction = function(//arguments) {//code block;}; . Alternatively, using declaration notation a function can be created by using the function keyword at the start of a statement to declare the function e.g. function myNewFunction(//arguments) {//code block;}.
  2. Bindings created using var gives that variable global scope, hence it is visible throughout the program. Bindings created using let (or const) are local to the block of code that they are declared in.
  3. A pure function is one that does not make use of side effects from other code such as global bindings, produces no side effects and is purely a value producing function. The value it produces with a given set of arguments will always be the same as it is not influenced by values or side effects beyond its scope.
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 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.
  2. What is the difference between var and let in regards to scope?
    -> let are variables that are limited to a block (for, if, white, etc), var can be globally
  3. What is a pure function?
    -> A pure function is a function where the return value is only determined by its input values, without observable side effects.
2 Likes

1 We create functions in javaScript using, Expressions, parameters and statements.

2 LET contain local variables to the block they are declared in. VAR is visible and contained throughout the whole function.

3 Pure functions produce the same output as the given input as a deterministic state.

2 Likes
  1. define a variable to hold a function value, declare a variable to be a function, arrow way
  2. let are variables limited to a block, var are global
  3. a pure function is a function without side-effect and also doesn’t rely on side effects from other code
1 Like

You create a function by using the keyword “function” then naming the function, then add a set of parentheses in which to enter arguments. Looks like: function heyDoThis ( arg1, arg2) { code goes here };

Var is global, let is limited to the block.

A pure function will always return the same value when given the same arguments and have no side effects. They also work in any context.

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

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

  3. A pure function is a specific kind of value-producing function that has no side effects but also doesn’t rely on side effects from other code.

2 Likes

Hi Academy! How are we today? :sunglasses:

  1. How can you create a function in Javascript?

The function keyword, when used as an expression, can create a function value. When used as
a statement, it can be used to declare a binding and give it a function as its
value. Arrow functions are yet another way to create functions.

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.

  1. The difference between var and let in regards to the Scope. The var and let - Both are keywords in JavaScript used to declare variables. The difference between var and let? The answer is Scope which determines whence variables are visible in our script.

  2. A pure function is a deterministic function . This means when the same input is passed every time, the function will return the same output. 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. More here;

Have a successful week, happy learning! :blush:

3 Likes
  1. Function x(y)={z};
  2. Var is a global variable. Let is a local variable.
  3. It’s is a function that has the same output and is not reliant on any other code.
2 Likes