Binding, Functions and Control Flow - Reading Assignment

  1. An expression is a fragment of code that produces a value. Expressions can contain other expressions and this allows us to build expressions that describe arbitrarily complex computations.

  2. Binding is a way to catch and hold values (way to remember things) in JavaScript programming. After a binding has been defined, its name can be used as an expression.

    But, when a binding points at a value, that does not mean it is tied to that value forever. Imagine bindings as tentacles, not boxes. Because bindings do not contain values; rather they grasp them.

  3. Environment is the collection of bindings and their values that exist at a given time.

  4. Function is a piece of program wrapped in a value.

  5. An example of a function that we have already been using in this course is console.log function (which we use to output values).

  6. Side effect can be showing a dialog box or writing text to the screen. It’s good to note that a lot of functions are useful because of the side effects they produce. Though, some functions may also produce values.

  7. An example of a function that produces a side effect is the prompt function which could show as a dialogue box in this example:

    prompt(“Enter passcode”);

    image

    (NOTE: Try this on you console to appreciate.)

    On the other hand, an example of a function that produces a value is, function
    Math.max , which takes any amount of number arguments and gives back the greatest. For example,

    console.log(Math.max(2, 4));
    // → 4

  8. Control flow is the flow of the execution of a program (contains more than one statement), from top to bottom. But we must keep in mind that control flow is not always a straight-line.

  9. In connection with answer number 8, an execution that doesn’t follow a straight-line flow is called conditional execution. Conditional execution happens when we want to create a branching road (as it is needed in the situation at hand).

  10. Conditional execution is created with the if keyword in JavaScript.

1 Like

1. What is an expression?

A piece (or line) of code that produces a value.

2. What is a binding?

A way to create a link to a value, that can be addressed in an expression

3. What is an environment?

A collection of bindings and their values at any given time.

An environment is always populated with at least the default bindings and values as part of the language standard.

4. What is a function?

Predefined code encapsulated that can be called using the defined name

Default function exist as part of the language standard but custom functions can be created.

5. Give an example of a function.

Prompt or console.log

6. What is a side effect?

The effect that the function produces

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

Prompt will produce a box and wait for user input.

Math.max will return a value based on the values supplies.

8. What is control flow?

The order of operations in which the code is run.

9. What is conditional execution?

The order of operations will depend on certain conditions being true or false.

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

The IF fuction.

1 Like
  1. What is an expression?

A fragment of code that produces a value, the expression is like a word, a statement is like a sentence and the program is then like the finished book

  1. What is a binding?

This is a link we create between values, so when you call one, the binded value appears.

  1. What is an environment?

The environnement is all the values and bindings that exists together at a time 0.

  1. What is a function?

A piece of program wrapped in a value, so calling the value can be applied to run the program.

  1. Give an example of a function.

The binding « prompt »

  1. What is a side effect?

A side effect is when a statement affects the world (display something on screen or else)

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

The command « prompt » produces a side effect as a dialog box appears o the screen

Math.max or Math.min are functions producing a value

  1. What is control flow?

This is the ordering of the different statements from top to botttom.

  1. What is conditional execution?

A conditionnal execution will take different paths according to the actual situation .

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

IF

2 Likes
  1. What is an expression?
    A fragment of code that produces a value.

  2. What is a binding?
    A value that is stored in memory to be uses later in the program.

  3. What is an environment?
    The collection of bindings and their values.

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

  5. Give an example of a function.
    The binding “prompt” that pops up a dialog box in a browser.

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

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

  8. What is control flow?
    Using keywords like “if” and “else” to control connections to values.

  9. What is conditional execution?
    Using a function like “Number.isNaN” (established a valid number) to set a condition for a value.

  10. What kind of keyword do you need to use to invoke conditional execution?
    The keywords “if” and “else”

2 Likes
  1. A fragment of code that produces a value
    2.Binding or a variable is a way to catch and hold values in Javascript.
    3.The environment is the collection of values and bindings that exist in a program at a particular time.
  2. Functions are one of the fundamental building blocks in JavaScript. A function in JavaScript is similar to a procedure - a set of instructions that performs a task or calculates a value, but for a procedure to qualify as a function, it must take some input and return an output where there is some obvious relationship between the input and the output.

function rectangle(number) {
return number * number;
}
6.A piece of code showing a text or a dialog box is a side effect. I guess we will have to also keep in mind that there is an unwanted side effect when the outcome of a piece of code or a function is not needed.
7. let y = 45
console.log ( “the value of y is” , y)
// the value of y is 45

console.log(Math.max(2, 4));
// → 4
8. The control flow in javascript is used to define the flow of instructions that are executed. If it were not for the control flows, the only thing we could do is execute one instruction after another and we would have no way of applying some functions or others according to the conditions that we want to establish.

A very typical practical example to understand the importance of control flow is the following: When we ask a user to enter her username and password, two things can happen. In the first place, that the data is correct and therefore we must let it log in or on the contrary that the user/password pair is wrong and therefore we must deny the entry and ask for the credentials again. As you see; Based on whether the credentials are correct or not, we must perform some actions or others. This is exactly what the control flow allows us to do.
9. It is a conditional statement of one or two branches. The control statement evaluates the logical or Boolean condition. If this condition is true then the statement or statements are executed. Otherwise, the statement that follows the else (if it exists) is executed.
10. IF , ELSE

1 Like
  1. What is an expression?
    A Code that leads to a value

  2. What is a binding?
    The method javascript uses to hold the value of something

  3. What is an environment?
    Is the collection of bindings at any given state

  4. What is a function?
    A function is a part of the code that that performs a task with values.

  5. Give an example of a function.
    console.log() is one of the functions we have been using to display values and computations in the console.

  6. What is a side effect?
    the text that is returned to the user is an example of a side effect. This is usually a string or variable that is shown to the user after function is invoked.

  7. Give an example of a function that produces a side effect and another function that produces a value.
    console.log() that I mentioned earlier produces a side effect because it reads back

math.max produces a value because it finds the greater of a set of numbers and produces it back to you.

  1. What is control flow?
    The order of which the code is executed. This is usually from top of the code to bottom of code.

  2. What is conditional execution?
    One of the exception to top to bottom control flow. Depending on the circumstances a program might follow one part of the code but ignore the other part.

  3. What kind of keyword do you need to use to invoke conditional execution?
    From the examples in the book, it seems like the words “IF” and “else” are keywords that invoke conditional executions.

1 Like
  1. A fragment of code that produces a value
  2. A name that ties itself to a value, aka a variable
  3. The collection of bindings and their values that exist at a given time
  4. A piece of program wrapped in a value
  5. Number(value) // converts value to a number type
  6. Any application state change that is observable outside the called function other than its return value.
  7. alert() produces the side effect of a popup box. Number() takes a string value and returns a number value
  8. The sequence in which statements are executed.
  9. Execution that only occurs if it fits certain conditions.
  10. if
2 Likes

What is an expression?

  • A fragment of code that produces a value.

What is a binding?

  • It is used to catch and hold values, its name can be used as an expression. The = operator can be used at any time on existing bindings to disconnect them from their current value and have them point to a new one.
  • Bindings refer to a value they don’t hold it. Two bindings can refer to the same value.

What is an environment?

  • The collection of bindings and their values that exist at a given time. It always includes default bindings that are part of the language standard, and usually also includes bindings that provide ways to interact with the surrounding system.

What is a function?

  • A piece of program wrapped in a value. It usually contains one or more lines of code that have a specific purpose and fit in the larger context of the program.
  • It accepts values called arguments and return one 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.

  • side effect: prompt(“Enter passcode”);
  • function that produces a value: Math.max(1, 4, 6)

What is control flow?

  • If your program contains more than one statement they are executed top to bottom. This is the control flow.

What is conditional execution?

  • When the program code contains conditions that cause the program flow to execute a certain branch of code depending on the condition(s) that apply and bypasses other branch(es).

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

  • if keyword
1 Like

1.An expression is a fragmented code that produces a value.
2.The purpose of binding is to catch or hold values.
3.An environment is a collection of bindings and their values at a given time.
4.A function is a piece of program wrapped in a value.
5. For example when on the browser the binding ‘prompt’ holds a function that displays a dialog box asking for a User Input. It could be like a drop-down menu asking for your email.
6. A side effect is a statement that affects other statement/values after it.
7. Some statements omit using a semi-colon but most need them. If you end a statement without a semicolon, there’s a good chance that it will affect the expression negatively. Max.max is a function that produces a value, in this case it produces the greatest value. //console.log(Math.max(2, 4));
// → 4
8. Control Flow is an operation of order for the code, the order is from top to bottom.
9. A condition execution is exactly what it sounds like. I believe you would use the commands ‘if’ this happens then do this. I don’t know how to write it yet but it’s a condition or a split in the road with given options based on a specific situation/condition.
10. “IF”

1 Like
  1. What is an expression?
    Any coding part program that produces a value.
  2. What is a binding?
    Anything than can hold a value
  3. What is an environment?
    Bindings and values than coexist at one point of time
  4. What is a function?
    Program wrapped in a value
  5. Give an example of a function.
    console.log(parameter)
  6. What is a side effect?
    Any state change that changes something to the program
  7. Give an example of a function that produces a side effect and another function that produces a value.
    side effect
    alert("these function prints this on my webpage)
    value
    Math.max(2, 1)
  8. What is control flow?
    The order for the program to executes the code generally from top to bottom
  9. What is conditional execution?
    The program can take two or more routes to continue
  10. What kind of keyword do you need to use to invoke conditional execution?
    if, else if, else
1 Like

Binding, Functions and Control Flow Reading Assignment.

1. What is an expression?

A expression is any fragment of code that produces a value.

2. What is a binding?

A “Binding” or “Variable” stores to current state of the program.
( It remembers and stores it assigned value )

3. What is an environment?

The “environment” is the collection of bindings and their values that exist at a given time.

4. What is a function?

A function is a piece of program wrapped in a value. such values can be applied in order to execute the “wrapped program”.

5. Give an example of a function.

alert("Hi welcome to the grocery webstore");
The alert is the function.

var input = prompt("How many liters milk do you want?");
The prompt is the function.

6. What is a side effect?

Showing a dialog box or writing text to the screen is a “side effect”.
A lot of functions are useful because of the side effects they produce.

Example from above : the prompt is the function, the resulting dialog box is the side effect.

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

The prompt function produces a side effect in the form of a dialog box.
Example : prompt("How many liters milk do you want?");

The Math.max function produces a value.
Example :

console.log(Math.max(2,4,6,8,10))
// --> 10

8. What is control flow?

When a program contains 2 or more statements, the statements are executed as if it was a story. “From top to bottom”

Example :
let thenumber = number(prompt("Pick a number")); console.log("your number is the square root of " + thenumber * thenumber);

( The prompt comes first to ask for a input because it is ABOVE the second line )

9. What is conditional execution?

Conditional execution is created with the “if” keyword. in a simple manner, we want some code to be executed if, and only if, a certain condition holds.

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

“if”

Example : here a response is generated only if the chosen number is less then 10.

let num = Number(prompt("pick a number"));
if (num < 10 {console.log("small"):}
1 Like
  1. Anything that produces a value is an expression in JavaScript.
  2. A Binding (aka - Variable) is a keyword assignment that catches and holds values for recall.
  3. An environment is a collection of bindings and their values that exist at a given time.
  4. A function is a piece of program wrapped in a value
  5. alert(“Hello World”)
  6. A side-effect is when an operation has an effect on a variable/object that is outside the intended usage.
  7. Example 1. prompt(“Enter Passcode”);
    Example 2. console.log(True)
  8. Standardized direction your program must follow. It should read like a story from top to bottom.
  9. When a program chooses a direction based on conditional instructions.
  10. If
1 Like
  1. What is an expression?
    variables and operators with values

  2. What is a binding?
    Allows you to borrow a method another object without making a copy of that method. Bindings don’t contain value but they “grasp” them from a location without changing it.

  3. What is an environment?
    The environment is the set of bindings that are defined to piece together.

  4. What is a function?
    a function is a set of information with a set value

  5. Give an example of a function.
    alert(“hello world”);

  6. What is a side effect?
    A side effect changes the observable outside the called function other than its return value. Side effects include: Modifying any external variable or object property

  7. Give an example of a function that produces a side effect and another function that produces a value.
    console.log() and Math.max

  8. What is control flow?
    A program containing more than a single statement, the statements are executed from top to bottom.

  9. What is conditional execution?
    Not a single straight route but a branching route, where the program takes the proper branch 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 Like
  1. A fragment of code that produces a value.
  2. A binding is when you capture or hold a value.
  3. An environment is a collection or bindings and their values.
  4. A function is a piece of program wrapped in a value.
  5. prompt (“Enter Passcode”);
  6. A side effect is when you change the internal state of the machine or affect all statements after the side effect.
  7. prompt (“sign at the dotted line”);
    let box = 4;
    box = 5;
    console.log (box + box);
    //10
  8. Control flow is the path the code is read, which is from top to bottom.
  9. A conditional execution is where you allow for different actions based on the data that is gathered.
  10. if
1 Like
  1. What is an expression?
    A fragment of code that produces a value is called an expression.

  2. What is a binding?
    Binding or variables are use to store values.

  3. What is an environment?
    The collection of bindings and their values that exist at a given time is called
    the environment .

  4. What is a function?
    A function is a piece of program wrapped in a value. Such values can be applied in order to run the wrapped program.

  5. Give an example of a function.
    For example, in a browser environment,
    the binding prompt holds a function that shows a little dialog box asking for
    user input. It is used like this:
    prompt(“Enter passcode”);
    Executing a function is called invoking , calling , or applying it.

  6. What is a side effect?

A side effect is produced by statements that generate changes in the world or the environment (changes on the machine that will affect the following statements to be run). Showing a dialog box or writing text to the screen is a side effect . A lot of functions are useful because of the side effects they produce.

  1. Give an example of a function that produces a side effect and another function that produces a value.
    Showing a dialog box or writing text to the screen is a side effect
    Functions may also produce values, in which case they don’t need to have a side effect to be useful. For example, the function Math.max takes any amount of number arguments and gives back the greatest.
    console.log(Math.max(2, 4));
    // → 4

  2. What is control flow?
    The order in which the statements are executed.

  3. What is conditional execution?
    We may, for example, want to create a branching road, where the program takes the proper branch based on thesituation at hand. This is called conditional execution .

  4. What kind of keyword do you need to use to invoke conditional execution?
    Conditional execution is created with the if keyword in JavaScript.

1 Like

1. Expression : is a fragment of code which returns a value.
2. similar to VARIABLE, binding is a section of RAM which contains a value. That value remains there until its re-assigned a new value or that section of RAM is unallocated.
3. Environment is the collection of bindings and their values.
4. function is a piece of program wrapped in and invoked by a value (function name).
5. alert() is a function which displays a massage on browser.
6. Side effect is the observable change in the environment other than the value returned by a function, such as a dialog box.
7. Side effect: Alert(“wellcome”); Value: Console.log(a && b)
8. Control Flow is the way which compiler executes statements from top to bottom.
9. Conditional Exec is the way functions are invoked if certain situation is present. Eg: IF (a * b != 5) { do this } Else { do this }
10. Keywords such as: If, Else, While, loop

1 Like
  1. What is an expression?

A fragment of code that produces a value

  1. What is a binding?

(aka a variable) - something that catches and holds a value

  1. What is an environment?

The collection of bindings and their values that exist at a given time

  1. What is a function?

A piece of program wrapped in a value

  1. Give an example of a function.

E.g. in a browser environment, the binding prompt holds a function that show a box asking for user input

  1. What is a side effect?

Showing a dialog box or writing text to the screen

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

prompt(“enter text”);
console.log(Math.max(2,3));

  1. What is control flow?

The execution of statements from top to bottom, when programs contain 1+ statement.

  1. What is conditional execution?

Unlike with control flow, conditional execution is not straightforward execution and allows for branches of execution, depending on the situation.

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

if, i.e. execute some code if and only if a certain condition holds.

1 Like

1. What is an expression?

A fragment of code that produces a value based on a given set of rules and conditions.

2. What is a binding?

A binding is when we connect a certain piece of memory to a certain value. That piece of computer memory is normally named after a word.

Example:

var age = 10; // We bind age with the value of 10.

3. What is an environment?

An environment is what we call to the state of the collection of bindings and their values at a given time.

4. What is a function?

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

5. Give an example of a function.

console.log()
prompt()
Math.random()

6. What is a side effect?

A side effect is any expression or function that a results in real and meaningful change, both in the upcoming statements or in the real world.

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

alert("")

Math.max(2,4)

8. What is control flow?

Control flow is the idea that when your program contains more than one statement, the statements are
executed as if they are a story and they make sense in terms of the chain of events.

9. What is conditional execution?

It’s a divergence in the code. Is when you execute different instructions based on what the input was.

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

if, for example

1 Like
  1. A fragment of code that produces an value.
  2. A binding is used to catch and hold values.
  3. A collection of bindings and their values at a given time is the environment.
  4. A piece of program wrapped in a value.
  5. console.log(“This is a function”)
  6. A side effect is any application state change that is observable outside the called function other than its return value.
  7. Prompt produces a side effect and console.log produces a value.
  8. Control flow is the direction that the program is executed. From top to bottom.
  9. Condition execution in Javascript is an if statement. The if statement directs the program flow depending on the values inputted into the if statement.
  10. “if” will invoke conditional execution.
1 Like
  1. An expression is code that produces a value.
  2. A binding stores the value of a variable for future use.
  3. An environment is the set of bindings and values that exist at the same time.
  4. A function performs a task on a value or binding
  5. prompt(“Hello”) function opens a prompt window with the strong “hello” written on it.
  6. The side effect has a result such as a comment box or section for the users to interact with after the function performs its task.

console.log(Math.max(5, 10)); is a function that produces a value and
prompt(“Enter passcode”); is function that has the side effect of the message pop up.
8. When the program includes more than one command, the program will run in sequence like a person reading a book from the top to bottom the program is executed in the sequence written.
9. When a condition is met the program performs a particular task. If the coin lands head the program does X tasks but if the coin lands tails the program does Y tasks.
10. If 
Program does X
Else 
the program does Y

1 Like