Binding, Functions and Control Flow - Reading Assignment

  1. A fragment of code that produces a value.
  2. Is the place that catch and hold values.
  3. Is the 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. function square(number) {
    return number * number;
    }
  6. Showing a dialog box or writing text to the screen.
  7. Side effect function: prompt(“Enter your name”); and function that gives value: Math.max(2, 4);
  8. Is the way how the program execute the statements one after another (from top to bottom) as if it is telling a story.
  9. Not all programs are straight flow, there might be branching flow and the program takes the proper branch based on the situation at hand.
  10. Keyword “if” is used to invoke conditional execution.
1 Like

1- an expressions is a fragment of code that produces a value
2- a binding holds and stores value, this helps a program keep its internal state and remember things
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, these values can be applied to run a wrapped program. A JavaScript function is executed when “something” invokes it (calls it).
5- function name ( parameter1, parameter2, parameter3 )
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) Logging to the console
7-

function sideEffect(errorMessage) {
alert(errorMessage); // This side effect can be seen on the screen!
}
function calculateAverage(valueA, valueB) {
return (valueA + valueB) / 2; // This function only returns the average without any side-effects!
}

8- Control flow is the order in which individual statements, instructions or function calls of a program are executed/ evaluated.
9- Conditional execution is when you specify boolean conditions resulting in the control flow of conditions. These control flow conditions can take different paths and perform different functions
10- “if” statements are used for conditional execution

1 Like
  1. A fragment of code that produces value is called an expression.

  2. Binding is a command for the program to catch and hold value.

  3. The collection of bindings and their values that exists at a given time is called the environment.

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

  5. prompt (“Enter Your Name”)

  6. Side effect is when a program or function change the state of something else outside its scope.

  7. Function that produces a side effect can be entering into console for example:
    alert (“hello”)
    it will prompt to press ok on the popup window

Produces a value:
sum = (2+4)
6

  1. Control flow is when a program contains more than one statement, statements are executed as if they are story, from top to bottom.

9/10. Conditional execution is when program takes a branch on the given situation that is invoked with a keyword ‘if’.

1 Like
  1. a fragment of code that produces a value
  2. a method of catching and holding values
  3. a collection of bindings and there values
  4. a peice of a program wraped in a value.
  5. console.log
  6. showing a dialog box or printing text
  7. alert(“hello”); and console.log(Math.max(3, 6);
  8. statements executed from top to bottom
  9. used for executing statements only if certain conditions are met
  10. if and else
1 Like

What is an expression?

Is a fragment of code that produces a value.

What is a binding?

Binding is used to catch and hold values. After binding is defined, its name can be used as an expression.

What is an environment?

Is a collection of bindings and their values that exist is the environment.

What is a function?

A function is a piece of a program wrapped in a value.

Give an example of a function.

Prompt, is a function in java script.

What is a side effect?

Changes displayed on the screen or changes to the internal of the machine to alter the statements that come after.

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

Math.max produces side effect, while math.min produces a value.

What is control flow?

Is a flow of statements in a program that tell a story the way they are executed from top to bottom.

What is conditional execution?

Is when code is executed only if certain conditions arise.

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

If

1 Like
  1. What is an expression?
    Any piece of code that ends up becomming a value.
  2. What is a binding?
    Allocating a certain place in memory to a variable and giving that variable a name.
  3. What is an environment?
    The collection of bindings and their values that exist at a given time.
  4. What is a function?
    A binding that instead of a value are binding to a set of instructions that are store in memory.
  5. Give an example of a function.
    function jacob (x,y){ return x *2 + y /3}
  6. What is a side effect?
    Changes that the function might create other than returning a value.
  7. Give an example of a function that produces a side effect and another function that produces a value.
    function jacobeffect(){alert(“Jacob is awesome”)}
    function jacobvalue() {return 5}
  8. What is control flow?
    The structure that control when instruction are executed and when instructions are not executed and in what order instrucions are executed.
  9. What is conditional execution?
    when a set of instruction are executed or not executed based on whether some condition fx 5 == x is true or not.
  10. What kind of keyword do you need to use to invoke conditional execution?
    if
1 Like

1- It is a fragment of code that produces a value. Every Value that is written for example: “15” or “football” are expressions.

2- It is when you reference a variable to a value.

3- It is a collection of bindings and the values that exist at a given time.

4- A function is a piece of program wrapped in a value . Eg console.log function. Such values can be applied in order to run the wrapped program.

5- console.log (Diogo)

6- Writing the text to the screen or showing a dialog box.

7- Produces side effect - alert and prompt. Produces a value - console.log (7+1).

8- Means that the statements are executed as if they were a story, from top to bottom.

9- Conditional execution means that not all programs are straight roads. We may want to create a branching road, when the program takes the proper branch based on the situation at hand.

10 - If

1 Like

An expression is a fragment of code that returns a value.

Binding is a value assignment to a variable that will hold that value. The keyword “let” tells the computer, that we are defining a variable. By using = operator, the previously attached value to a binding can be updated and assigned a new value.

It is a collection of bindings and their values existing at a given time. At a start up of a program, an environment contains these lines of code in order for the program to interact with interfaces.

A function is a block of code, that can take a value or multiple values and compute them together in a preset way.
A function can be reused over and over agin, to produce outputs from different inputs.

alert(“Hello World!”) is a function. It took the argument “Hello World!” and displayed it in a pop-up alert in the browser.

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

prompt(“How are you today?”);
Math.max(); will return a value that is the highest in the list of arguments it was given.

JavaScript reads and executes code from top to bottom.

Conditional execution is branching out into options given in the code, based on the inputs given to a function.

1 Like
  • What is an expression?

An expression is a ‘fragment of code’ that produces some kind of value.

  • What is a binding?

A binding is something that catches or holds value.

  • What is an environment?

An environment is the where we hold all binding and their values in JS.

  • What is a function?

A function is a small piece of programing that can be represented by one value.

  • Give an example of a function.

prompt() is a function that will cause a ‘prompt’ to pop up on the screen. Math.max() and Math.min() find the max and minimum (respectively) of the numbers listed within the parentheses.

  • What is a side effect?

A side effect is something that will alter the current state of the program, like a ‘prompt’ popping up or a dialog asking for information from the user.

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

prompt() gives a side effect while Math.min() gives a value.

  • What is control flow?

Control flow describes how the computer will read and understand your statements.

  • What is conditional execution?

Conditional execution is exactly what it sounds like. If a program produces a specific value that meets certain ‘conditions’ then the program will be ‘executed’ a certain way. If not, it will be executed another way.

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

Conditional executions in JavaScript are; ‘if’, ‘else’ and ‘switch’.

1 Like

What is an expression?

A fragment of code that produces a value is called an expression

What is a binding?

A binding catch and hold values,

What is an environment?

The collection of bindings and their values that exist at a given time is called the environmen

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 is a side effect.

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

For example, the function Math.max takes any amount of number arguments and gives back the greatest.

What is control flow?

When your program contains more than one statement,

What is conditional execution?

where the program takes the proper branch based on the situation at hand. This is called conditional execution.

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

the if statement

1 Like
  1. What is an expression?

An expression is a fragment of code that produces a value.

  1. What is a binding?

A binding is a JavaScript tool that allows the user to “catch and hold” (or bind) a value.

  1. What is an environment?

An environment is a collection of bindings and values that exist at any given time.

  1. What is a function?

A function is a piece of program wrapped in a value.

  1. Give an example of a function.

The prompt function makes a window pop up for the user so they may enter information.

  1. What is a side effect?

A side effect is 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 passcode”);

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

  1. What is control flow?

Control Flow is controlling the way and order in which statements are executed.

  1. What is conditional execution?

Condition Execution is branching away from a straight-line control flow in order to allow the program to follow the right path based on the situation.

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

If, else,

1 Like
  1. What is an expression?
  • A fragment of code that produces a value.
  1. What is a binding?
  • It’s a variable. Placeholder for data.
  1. What is an environment?
  • An environment is the collection of elements and values in one place at one time.
  1. What is a function?
  • A program is a task set within the values. A function makes things happen. A function prints something to screen, affects the program and causes a change for the following program.
  1. Give an example of a function.
  • console.log(Math.min(13,24,56,43,62) - 12);
  1. What is a side effect?
  • A side effect is an occurrence from a function (either wanted or otherwise). This could be text on a screen, or internally jump to another piece of code as (function) programmed.
  1. Give an example of a function that produces a side effect and another function that produces a value.
  • alert(“hello world”);
  • console.log(5 * 5);
  1. What is control flow?
  • The flow of the code … order in which it should be written / read.
  1. What is conditional execution?
  • If the code has options and makes a decision based on input - changing the path of the code.
  1. What kind of keyword do you need to use to invoke conditional execution?
  • ‘if’ to invoke and ‘else’, ‘if’ following as required.
1 Like
  1. An expression is a fragment of code that produces a value
  2. A binding is used to catch or hold values
  3. An environment is a collection of binding and their values in a given time.
  4. A function is a piece of code wrapped into a value
  5. An example could be: let num = Number(prompt(“Pick a number”));
  6. A Side Effect is a sentence that appears in your console, it shows off when evocking a function. It shows any application state change observable outside the invocked function.
    7 Example of a function giving a value;
    console.log(Math.max(2, 4));
    // → 4
    Example of a function giving a side effect:
    let ivan = true
    ivan
  7. It’s the left to the right, top to the bottom logic used to write and read code on javascript
  8. Conditional execution allows the program to take the proper branching road based on the situation at hand.
  9. Conditional execution is invoked with the word “if”
1 Like
  1. An EXPRESSION is a fragment of code that produces a value
  2. A BINDING explictly assigns X to be a specific value. It is a way to catch and hold a value.
  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

var a =1
var b =2
console.log((a*b)+b)

  1. SIDE EFFECT is when you show a dialog box or writing text to the screen
    When a function produces a value, it is said to return that value. A side-effect is when a functiona procedure changes a variable from outside its scope. It compromise the purity of a function.
  2. prompt(“Enter passcode”); has the side effect of a prompting dialogue box.

    an alert("alert is a function that produces a side effect, it opens a window
    console.log(2+4); produces a value.
    8.CONTROL FLOW is that the statements are executed as if they are a story, from top to bottom. 9. A CONDITIONAL EXECTION is when the program decide what to do based on certan condition. It is a branch in the control flow’s execution.
    10 IF is the kewyord to invoke conditional execution.
    But there can be also ELSE, ELSE IF, SWITCH
1 Like

What is an expression?
In mathematics, an expression or mathematical expression is a finite combination of symbols that is well-formed according to rules that depend on the context. In JavaScript (and other software languages) 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.

What is a binding?
Sometimes known as Data binding is when, you have a data model and on the other side, you have an interface, often called a view. The idea is that you want to “bind” some piece of data to something on the view so that when the data changes, the view changes.

In JavaScript, Function binding. Uses the Bind() method to call a function with the this value, this keyword refers to the same object which is currently selected . Meaning, the bind() method allows one to easily set which object will be bound by the this keyword when a function or method is invoked.

Everything tracked by JavaScript is bound. In fact, the definition of undefined means JavaScript cannot find a bound identifier. Binding something in JavaScript means recording that identifier in a specific Environment Record. Each Environment Record is related to a specific Execution Context - and that binds the identifier (variable or function name) to the this keyword for that execution context.

Think of Environment Records as buckets of stuff. These are not Objects or Functions or Variables or anything we code in JavaScript, these buckets contain all these things. There are many buckets in a JavaScript application. Each bucket operates independently from the other buckets. That independence is represented as a Context (or Execution Context) in JavaScript. But sometimes we want to use stuff from one bucket inside a different bucket. That is where binding comes in. We can bind stuff from one bucket into the context of a different bucket for execution there. (A side effect of doing all that is the this keyword reflects the bucket borrowing the stuff).

What is an environment?
A Lexical Environment is a specification type used to define the association of Identifiers to specific variables and functions based upon the lexical nesting structure of ECMAScript code. A Lexical Environment consists of an Environment Record and a possibly null reference to an outer Lexical Environment.

What is a function?
A JavaScript function is a block of code designed to perform a particular task. Inside the function, the arguments (the parameters) behave as local variables. Functions are one of the fundamental building blocks in JavaScript. A function is a JavaScript procedure—a set of statements that performs a task or calculates a value.

Give an example of a function

function myFoo(param1, param2) {
  return param1 * param2;   // The function returns the product of param1 and param2
}

What is a side effect?
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).

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

Produces Side Effect
console.log()

Produces Value
Math.random()

What is control flow?
The control flow is the order in which the computer executes statements in a script. A typical script in JavaScript or PHP (and the like) includes many control structures, including conditionals, loops and functions. Parts of a script may also be set to execute when events occur.

What is conditional execution?
Conditional statements are used to decide the flow of execution based on different conditions. If a condition is true, you can perform one action and if the condition is false, you can perform another action.

What kind of keyword do you need to use to invoke conditional execution?
if, while and do loop

2 Likes

1. What is an expression?

An Expression is a piece of code that produces a Value, meaning “it becomes a value”.


2. What is a binding?

Binding is the statement that allows JS to hold Values.
The binding statement uses words such as (let, var, const), which are not the same.

A binding looks something like this:
Special word (keyword) + Binding name = Value

Ex: var a = 5; // a = 5


3. What is an environment?

As the book says, the Environment is the collection of bindings and their values that exist at a given time inside the program.

4. What is a function?

A Function is one of the fundamental building block in JS. It is represented by a set of Statements that perform a task or calculates a line. More easily explained, it is a unit of computation which takes an input and produces an output.


5. Give an example of a function.

console.log(‘Fresh’ + ’ ’ + ‘air’);
// Fresh air

6. What is a side effect?
A side effect is the way that a function “communicates” with the outside world. Ex. “message on screen, sound, mail sent etc.”.

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

Function with Side Effect

Side effect

Function with Value

Value


8. What is control flow?

Control Flow represents an “ascending” order of executing the statements inside a program. Easier said, statements executed in a straight line.


9. What is conditional execution?

A Conditional Execution is represented by the “branching road” a program takes in order to execute, based on the given situations.


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

For the moment, I know only if and else

2 Likes
  1. An expression is any type of code that produces a value
  2. A binding is the same as variable, it can be used to point a phrase or word to a value
  3. Environment is the collection of bindings and values that exist at any given point in time
  4. A function is a piece of program wrapped in a value
  5. The one given in the book is prompt(“Enter passcode”); This will prompt the user to enter the passcode in order to proceed
  6. A side effect is showing a dialog box or writing text on a screen
  7. The dialog box produced from the prompt to enter passcode prompt(“Enter passcode”); is a side effect. A person typing in their passcode is a side effect.
    The value of 4 shown below is a value as it’s the end result of the calculation.
    console.log(Math.max(2, 4));
    // → 4
  8. It’s the order of flow that a program will follow. Programs will read the language from top to bottom, left to right
  9. Conditional execution is like a fork in the road. Depending on an initial calculation the program will take the appropriate for, and go on from there.
  10. If keyword is what invokes conditional execution
1 Like

Nice, I bet you learned a lot from this answer?

very good !

Ivo

1 Like

Yes Ivo. It helped me understand things better. Did some research on the side, but things are much clear now :slight_smile:

1 Like
  1. A fragment of code that produces a value is an expression. A value itself can be an expression, and an expression can contain other expressions. An expression in like a subsentence or a fragment of a statement.

  2. Is what catches and holds values or variables. We must think in them as if they were tentacles rather than boxes. To create them we use let, var or const.

  3. Is the collection o bindings and their values ina given time.

  4. A function is a piece of program wrapped in a value. They produce an action when executed. Every function needs a number of arguments.

  5. Math.max(2, 4)

  6. A side effect is what function produces beyond the console. Can be displaying something in the screen or changing the internal state of the machine and hor the coming statements will works.

  7. No side effect. console.log(10 * 10). Side effect: alert(“hello world”)

  8. The way the statements are read. From top to bottom, or right to left. The machine executes statements as if it were an story.

  9. Is a program with different branches or paths to follow depending on a given condition. It will have some boolean expresions. conditions are introduced with “If” and “else”.

  10. If and else and boolean expressions.

1 Like