Binding, Functions and Control Flow - Reading Assignment

Welcome to the discussion about the reading assignment about Binding, Functions and Control Flow.

Leave your answers to the questions below in this thread. If you have any questions or you want to discuss something connected to the assignment feel free to do it in this thread as well, but please everything to the topic.

  1. What is an expression?
  2. What is a binding?
  3. What is an environment?
  4. What is a function?
  5. Give an example of a function.
  6. What is a side effect?
  7. Give an example of a function that produces a side effect and another function that produces a value.
  8. What is control flow?
  9. What is conditional execution?
  10. What kind of keyword do you need to use to invoke conditional execution?
56 Likes

1.An expression is any piece of code that resolves to a value.

2.A binding(variable) is a named piece of computer memory, containing some information inside.

3.An environment is set of variables and their values that exist in memory at a given time.

4.A function is named section of a program that performs a specific task.

5.alert(“I am an argument”);

  1. If a statement or function modifies the state of something else (outside its own scope), then it is
    producing a side effect.

  2.  let num = 0;
      const func = () => {
        num = 1;
        return true;
      }
      func();
    
  3. Control flow is simply the order in which we code and have our statements evaluated.

  4. Conditional execution means that some part of the code is going to be executed only if certain condition
    is fulfilled( true ).

10.Conditional expressions, for example IF …

20 Likes

1- Fragment of code that produces a value is called an expression. a is expression and b is expression. a*b; is a statement. Every value that is written literally is an expression. expression with operators ending with semicolon makes the statement.

2- Binding is a way a program keeps an internal state. Binding stores value so that we can use it later. Binding is a variable.
let caught = 5 * 5;
let is a keyword that defines a binding and it is naming this binding with name > caught.
Keywords that define a binding are many and these are:
break case catch class const continue debugger default delete do else enum export extends false finally for
function if implements import interface in instanceof let new package private protected public return static super switch this throw true try typeof var void while with yield

3- Collection of bindings and their values that exist at a given time is called the environment. When program starts environment is not empty. e.g. Browser environment.

4- Piece of program wrapped in a value is a function. In browser environment, binding prompt holds a function that shows a little dialog box asking for user input.
prompt(“Enter your name”);
or
function myFunctionName(p1, p2) {
return p1 * p2;
}

5-
prompt(“Enter your name”);
or
function myFunctionName(p1, p2) {
return p1 * p2;
}
or
alert(“hi there”);

6- Showing a dialog box or writing text to the screen is a side effect.

7-
side effect example
prompt(“Enter your name”);
value example
console.log(Math.max(2, 4));
it will output a value that is 4
Side effect is kind of action that is performed in an environment but value is a result that is displayed by a function via return.
When a function produces a value, it is said to return that value.

8- When your program contains more than one statement, the statements are executed as if they are a story and this is control flow. straight-line control flow.

9- Not all programs take straight-line control flow. We may, want to create a branching road, where the program takes the proper branch based on the situation at hand or condition that we give it. This is called conditional execution. Conditional execution is achieved with the if and else keywords.

10- if and else.

22 Likes
  1. An expression is any valid set of literals, variables, operators, and expressions that evaluates to a single value. The value may be a number, a string, or a logical value. Conceptually, there are two types of expressions: those that assign a value to a variable, and those that simply have a value
  2. bindings are like tentacles, they dont hold any information but they grasp them, to bindings can point to the same value
  3. the collection of bindings and their values that exist at a given time is called environment
  4. A function is a wrapped section that performs a specific task
  5. alert(“Im rich and handsome”)
  6. A side effect is any application state change that is observable outside the called function other than its return value. Side effects include: Modifying any external variable or object property (e.g., a global variable, or a variable in the parent function scope chain)
  7. let num = 0;
    const func = () => {
    num = 1;
    return true;
    }
    func();
  8. Control flow is the order in which we code and have our statements evaluated
    9.conditional execution means that a condition is only executed when it meets predefined condition
  9. if, if else, while, loop, true/false
4 Likes
  1. An expression returns a value
  2. Binding is when you point/reference a variable to a value
  3. Environment is the the collection of bindings and their values at that point in time of the programs existence.
  4. A function is a group of code that can be called by the program to compute a value
  5. isNan() is a global function example… used to evaluate if a value is an illegal number
  6. Side effect is a statement result that changes something that affects the program
    7.isNan() would produce a value, Number() would produce a side effect by converting a value to a number
  7. Control flow is the way the program is executed. Javascript control flow is top to bottom like humans read a page.
  8. Conditional execution is like a fork in the road. The program uses if, else, if else to evaluate a condition and continue executing the branch of code based on the value returned from that condition.
  9. if, else, else if
4 Likes
  1. What is an expression?
  2. An expresion is any fragment of code that results in a value.

  3. What is a binding?
  4. A binding or a variable is assignment of internal state used to catch and hold values. By using the keyword `let` before defining a variable lets JavaScript know the sentence is going to define a variable.

  5. What is an environment?
  6. The enviroment is the collection of bindings and their values existing in a given instance.

  7. What is a function?
  8. A function is an expression wrapped in a value. It can be executed by calling it.

  9. Give an example of a function.
  10. web3.eth.getAccounts(function(e,accounts);


  11. What is a side effect?
  12. A side effect is a function which produces an expression and returns that value.

  13. Give an example of a function that produces a side effect and another function that produces a value.
  14. console.log(firstAccount);
    var firstAccount = accounts[0];

  15. What is control flow?
  16. It is the direction of execution of code in JavaScript which happens in a top down approach.

  17. What is conditional execution?
  18. Conditional Execution is a branch in the control flow's execution, where JavaScript picks a branch depending if the conditions that are present.

    Example:

    if(typeof web3 !== "undefined")

    else{alert("Could not find Web3.0 provider. Please visit metamask.io or download the Ethereum Mist browser");

  19. What kind of keyword do you need to use to invoke conditional execution?
  • Use

    if

    to specify a block of code to be executed, if a specified condition is true

  • Use

    else

    to specify a block of code to be executed, if the same condition is false

  • Use

    else if

    to specify a new condition to test, if the first condition is false

  • Use

    switch

    to select one of many blocks of code to be executed

Source: w3bschools

21 Likes
  • What is an expression?
    • An expression is any piece of code that returns a value, expressions can be layered with other expressions making larger expressions.
  • What is a binding?
    • A binding is a value or string set to a variable, it helps to make bindings so you don’t have to write out the same expression multiple times in the program.
  • What is an environment?
    • An environment is all of the bindings that have been made within a program.
  • What is a function?
    • a function is a section of the program that performs a specific task. It can then be called upon for use in other expressions.
  • Give an example of a function.
    -alert(“This message will self destruct”);
  • What is a side effect?
    • A side effect is any expression or function that displays or otherwise changes the string or value on the webpage, basically if the program changes visibly it is a side effect.
  • Give an example of a function that produces a side effect and another function that produces a value.
    • prompt(“How are you liking the course?”);
  • What is control flow?
    • Control flow is the order in which a program will execute the code.
  • What is conditional execution?
    • Conditional execution is used when a website has input from a user, it allows the program to behave differently based on different information being entered or manipulated by the user.
  • What kind of keyword do you need to use to invoke conditional execution?
    • if, else
5 Likes
  • What is an expression?
  • An expression is code that produces a value.
  • What is a binding?
  • A binding is a special rule for a variable involving a key word to give direction to the binding. Consider the words DO and SOMETHING. DO is the special word and SOMETHING is the variable. Together they form a binding.
  • What is an environment?
  • An environment is the collection of bindings that exist at a given time.
  • What is a function?
  • A function is a piece of a program wrapped in a value.
  • Give an example of a function.
  • alert("alert is a function"); .
  • What is a side effect?
  • A side effect is an observable change in the state of the application
  • Give an example of a function that produces a side effect and another function that produces a value.
  • alert("alert is a function that produces a side effect")
    console.log(2+4); produces a value.
  • What is control flow?
  • Starting top to bottom, the execution flow when you have more than one statement.
  • What is conditional execution?
  • A point where the program decides what to do based certain conditions.
  • What kind of keyword do you need to use to invoke conditional execution?
  • There are more than one but the word 'if' is needed regardless.
7 Likes

What is an expression?
- A fragment of code which outputs a value is an expression.

What is a binding?
- Binding is the establishment of a connection between two values. In the example: ( let caught = 5 * 5; ) the equal operator is applying a connection between “caught” and the answer of 5*5 essentially defining and setting a new variable.

What is an environment?
- All the bindings and their values which exist is the environment.

What is a function?
- A function is a piece of programming wrapped in a value.

Give an example of a function.
-console.log (""); is a function which outputs some information to the console.

What is a side effect?
- A dialogue box or writing text to the screen is a side effect.

Give an example of a function that produces a side effect and another function that produces a value.
- prompt(“Enter passcode”); has the side effect of a prompting dialogue box.
- console.log(Math.max(2, 4)); produces no side effect, though produces a value.

What is control flow?
- The order of executing code from top to bottom left to right.

What is conditional execution?
- When using a logical operator to determine wether or not to execute certain parts of the code.

What kind of keyword do you need to use to invoke conditional execution?
- ‘if’ is the keyword to invoke conditional execution.

1 Like
  1. What is an expression?
    Expression is anything that is written as a string or number.
  2. What is a binding?
    A pointer that is tied to value and can be disconnected and point to a new one.
  3. What is an environment?
    Collection of bindings and their values that exist at a given time.
  4. What is a function?
    A line of code within a block that can be called as often as needed
  5. Give an example of a function.
    The random() in Math.random(). Every time it is called it gives a random decimal number from 0 to 0.9999999999.
  6. What is a side effect?
    Showing dialog box or text to the monitor. A
  7. Give an example of a function that produces a side effect and another function that produces a value.
    console.log produces side effect and Math.max produces a value.
  8. What is control flow?
    Is the order in which the computer executes statements in a script.
  9. What is conditional execution?
    Uses the ‘if’ keyword and uses a certain condition whether the value is truthy or falsey and takes one path instead others had the value been different.
  10. What kind of keyword do you need to use to invoke conditional execution?
    if
1 Like

1.What is an expression?

An expression in a programming language is a combination of one or more explicit values,
constants, variables, operators, and functions that the programming language interprets
(according to its particular rules of precedence and of association) and computes to produce
(“to return”, in a stateful environment) another value.

  1. What is a binding
  • Data binding, the technique of connecting two data elements together
  • Binding, associating a network socket with a local port number and IP address
  • Name binding, the association of code or data with an identifier in a programming language
  1. What is an environment

it is the collection of variables and their values that exists at a given time.

4.What is a function?

A function is a piece of program wrapped in a value. Generally, this piece of program does
something useful, which can be evoked using the function value that contains it.

  1. Give an example of a function.

the variable alert, for example, holds a function that shows a little dialog box with a message.

6.What is a side effect?

is said to have a side effect if it modifies some state outside its scope or has an observable
interaction with its calling functions or the outside world besides returning a value

  1. Give an example of a function that produces a side effect and another function that produces a
    value.

    console.log produces side effect and Math.max produces a value.

  2. What is control flow?

Is the order in which individual statements, instructions or function calls of an imperative program
are executed or evaluated.

9.What is conditional execution?

When we don’t want that some part of a statement(s) in the program is not executed in function of some conditions,
we introduce a conditional execution, if the condition is respected, the statement will be executed,
in other case, the statement will not be executed and the progam continue the execution further

10.What kind of keyword do you need to use to invoke conditional execution?

IF

1 Like
  1. a fragment of code that produces a value
  2. binding is giving an element a value so it can be stored in it.
  3. is a collection of bindings and their values in a certain frame of time.
  4. a piece of program warped in a value, is a price of code that performs a specific task and usually returns a value.
  5. prompt, alert, console.log
  6. If a statement or function modifies the state of something else (outside its own scope), then it is
    producing a side effect.
  7. prompt(“Enter your name”);
    value example
    console.log(Math.max(2, 4));
    it will output a value that is 4
  8. Control flow is wow the program is executed (from top to bottom).
  9. is a function that allows the program execute some code if the statement provided agrees with the condition.
  10. IF
1 Like
  • What is an expression? code to generate a value
  • What is a binding? hold values
  • What is an environment? collection of bindings and their actuals values
  • What is a function? a method,
  • Give an example of a function. public sum(n){ var a = 1, b=2, s=a+2; return s };
  • What is a side effect? Showing an alert or dialog box
  • Give an example of a function that produces a side effect and another function that produces a value. console.log(Math.max(2, 4));
  • What is control flow? keep the sequence of the sentences in the program
  • What is conditional execution? it is a funtion to condicionate the execution of a statement
  • What kind of keyword do you need to use to invoke conditional execution? If, while and do loop
2 Likes
  1. An expression is a fragment of code that generates a value.
  2. A binding, also called variable, is a named storage for holding a value. It allows a program to keep an internal state. A binding can be defined with one of the keywords var, let or const.
  3. The environment is the collection of all bindings with their values that exist at a given point of time.
  4. A function is a piece of code wrapped in a value. It can be executed by applying (also called evoking or calling) it.
  5. Function example: prompt
  6. Functions produce side effects if they modify states outsides its scope, i.e. executing code that is not involved in calculating the return value but still influences the program after the function call.
  7. Function producing side effect: console.log; Function producing a value: Math.pow
  8. Control flow defines the order in which the program statements are executed.
  9. With conditional execution certain parts of the code are only executed if a certain condition is fulfilled, i.e. it enables code to branch.
  10. if
2 Likes

What is an expression?
fragment of code that produces a value is called an expression.

What is a binding?
Binding, or variable catches and holds values ​

What is an environment?
The environment is a collection of bindings and their values that exist at a given time​

What is a function?
A function is a piece of program wrapped in a value. ​

Give an example of a function.
prompt(“enter passcode”);

What is a side effect?
Side effects happen when a statement changes the world environment or changes the internal state of the machine and affects the statements that come after it.

​Give an example of a function that produces a side effect and another function that produces a value.
1. side effect: console.log (a);
2. value: let a = 1;​

What is control flow?
control flow ensures that statements are executed in the proper order

What is conditional execution?
this is where the program can execute different statements depending on the situation presented

What kind of keyword do you need to use to invoke conditional execution?
The If Then Statement would be an example of a conditional execution

1 Like

1. What is an expression?
A fragment of code that produces a value.
2. What is a binding?
A binding is the same thing as a variable. It is tying or pointing a specified name to a value, for later use.
3. What is an environment?
A collection of bindings and their values existing at a given time.
4. What is a function?
It is a named section in a program that performs a specific task.
5. Give an example of a function.

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

6. What is a side effect?
A side effect is a change that affects the internal state of the machine in a way that will affect the statements that come after it.
7. Give an example of a function that produces a side effect and another function that produces a value.

function addTen(value){
return value+10;
}

function multiplyBy2(val) {
val*2;
}

8. What is control flow?
The order in which statements are executed.
9. What is conditional execution?
This is where the program takes the direction based on the situation at hand.
10. What kind of keyword do you need to use to invoke conditional execution?
if, else if and else

  1. An expression produces a value
  2. collection ofm binding and their values
  3. environment is the existing code program
  4. a Function is piece of program wrapped in a value
  5. prompt
  6. change the internal state the affect what comes after
  7. let theNumber = Number(prompt(“Pick a number”));
    if (!Number.isNaN(theNumber)) {
    console.log("Your number is the square root of " +
    theNumber * theNumber);
    }
  8. program that contains more than one statement
  9. code that will only execute based on a specific result
    10.else
  1. A piece of code that produces a value
  2. Several expressions nested or combined to make a more complex expression
  3. A collection of variables and their existing values a any given time
  4. A piece of program wrapped in a value, which can be executed in order to run this wrapped program.
  5. alert ("hello world);
  6. Changing statement that could change the internal state of a machine and the statements that come after it, with functions it can be having a dialog box or writing text on the screen
  7. “Confirm” function produces an extra window, Math.max just gives a value
  8. It’s the order in how statements are executed, this can be straight from top to bottom, in conditional way or with loops
  9. It’s an execution in which we can take two different routes based on the outcome value of a boolean expression
  10. “If” keyword

1- Expression is a chunk of code which returns a value

2- Binding is the way we have to link a value to a word

3- Environment is the whole set of variables and functions which allow us to communicate with the app who is running JS

4- A function is an encapsulated piece of code in charge of doing something

5- function add(a, b) { return a + b; }

6- Side effect is when a piece of code modify any state, ie. printing screen or reassign a variable

7-
function sideEffect(){ console.log(“Hola”) }
function pureFunction(a) { return a + 1 }

8- Control flow are the rules we give to a program to do something instead of other thing based on a condition

9- Conditional execution is when a block of code is executed only if a condition is met

10- if { } else if { } else { }

3 Likes

What is an expression?

A fragment of code which produces a value. For example “22” or “psychoanalysis”

What is a binding?

Bindings (also known as variables) are used to catch and hold values

What is an environment?

The collection of bindings that exist at a given time is known as the environment

What is a function?

A function is a piece of program wrapped in a value

Give an example of a function.

prompt(“Enter passcode”);

What is a side effect?

Showing a dialog box or writing text to the screen

Give an example of a function that produces a side effect and another function that produces a value.

console.log = side effect
console.log(Mat.max(2, 4)); = value
(This is hard to fully understand and I’m mostly guessing)

What is control flow?

The order in which statements are executed within a program

What is conditional execution?

It’s where the program takes the proper branch based on the situation at hand

What kind of keyword do you need to use to invoke conditional execution?

If

1 Like