Binding, Functions and Control Flow - Reading Assignment

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

  2. A method used to catch and hold values is called a binding. It is also referred to as a variable.

  3. The collection of bindings and their values that exist at a given time is - environment.

  4. A function is a piece of program wrapped in a value. Executing a function is called invoking, calling, or applying it.

  5. A JavaScript function is defined with the function keyword, followed by a name , followed by parentheses ()
    (ex. prompt(“Enter passcode”); )

// Convert Fahrenheit to Celsius
function toCel(F) {
return (5/9) * (F-32);
}

6.A side effect - An expression that changes the internal state with in the program that affects the statements that come after it.

  1. let num = value(prompt(“Pick a number”));
    if (num < 1) {
    console.log(“Small”);
    } else if (num < 10) {
    console.log(“Medium”);
    } else {
    console.log(“Large”);
    }
  2. When your program contains more than one statement, the statements are
    executed from top to bottom.
  3. With conditional execution code is executed only if a certain condition is met.
  4. The IF command is used used to invoke conditional execution.
1 Like
  1. What is an expression?
  • Any fragment of code that produces a value
  1. What is a binding?
  • A binding is how a program keeps an internal state in memory. They are also called variable and are declared with the keyword “let” or “const”
  1. What is an environment?
  • It is the collection of all bindings and their values that exist at a specific time
  1. What is a function?
  • A function is an fragment of code that can be called by its name. It may have arguments and may return a value.
  1. Give an example of a function.
 function add(arg1, arg2){
    return arg1+arg2;
 }
  1. What is a side effect?
  • It is a when a statement changes the world or the internal state of the machine: produces a side effect or a value.
  1. Give an example of a function that produces a side effect and another function that produces a value.
  • The “console.log” function produces the side effect of logging a given input onto console screen.

  • An assignment/binding such as the function given at #5 produces a value.

  1. What is control flow?
  • Control flow is the execution of the statements that are fed into the machine from top to bottom unless otherwise modified by the conditional executions of code using flow control functions such as if, while, for.
  1. What is conditional execution?
  • It is when an expression is only executed if it fulfills the condition. It is marked by one of the flow control functions followed by the test condition that should result in a Boolean value of true or false.
  1. What kind of keyword do you need to use to invoke conditional execution?
  • Flow control functions such as if, while, for.
1 Like
  1. What is an expression?

A fragment of a code that produce value is called expression.
Every value that is written literally is an expression.
An expression between parentheses is also an expression.
This allows us to build expressions that describe arbitrarily complex computations.

  1. What is a binding?

To catch and hold values, JavaScript provides binding, or variable.
et is the keyword to indicate that this sentence is going to define a binding.
Binding is like a tentacles rater than boxes. When you have to remember something you use a tentacle to hold on it or to attach one of the existing tentacles.

  1. What is an environment?
    The environment is a collection of bindings and theyre value to a given time. The environment always contains bindings that are part of the language standard. The environment has also bindings that provide ways to interact with the surrounding system.

  2. What is a function?
    A function is a piece of program wrapped in value.
    Executing a function is called invoking, calling, or applying it.

  3. Give an example of a function.
    Browser environment binding prompt holts a function thats show a dialog box asking for user input.

  4. What is a side effect?
    A side effect is an application state change that is observable outside the called function other than
    its return value.

  5. 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.

  6. What is control flow?
    The control flow is the order in which the computer executes statements in a script.

  7. What is conditional execution?
    The program execution is based on condition. Its not straight forward.

  8. What kind of keyword do you need to use to invoke conditional execution?
    The keyword to invoke conditional execution is if.

1 Like
  1. An expression is code that produces a value.

  2. A piece of code that points to a value

  3. A library of bindings with their current values

  4. A piece of program wrapped in a value.

  5. prompt(“Enter passcode”), alert(“Warning!”)

  6. Showing a dialog box or writing text to the screen

Side effect: alert(“Warning!”),
Value: console.log(2+4)

  1. The order in which statements are executed

  2. A branching road, where the program takes the proper branch based on the
    situation at hand.

  3. if, else if, else

1 Like
  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
1 Like
  1. A fragment of code that produces a value is called an expression.

  2. To catch and hold values, JavaScript provides a thing called a binding, or variable.

  3. 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. prompt(“Enter passcode”);

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

  7. prompt(“Enter passcode”); and console.log(Math.max(2, 4));

  8. The order the statements in the program are executed - left to right and top to bottom.

  9. Conditional execution is a special order of statements execution when some code is executed if, and only if, a certain condition holds.

  10. if, else, else if

1 Like

Answers

  1. An expression is a piece of code that produces a value. If an expression corresponds to a sentence fragment, a statement is a full sentence. A program is a list of statements.

  2. Binding, or variable, exists in order to catch and hold values. Keyword let express that a sentence is going to define a binding. It’s followed by the name of the binding, an operator and an expression (for instance: let age = 30).

  3. An environment is the collection of bindings and their values in a program and on the surrounding system, for example in a browser.

  4. A function is a piece of program wrapped in a value. Values should be applied in order to run the wrapped program. Executing a function is called invoking or calling it. Values given to functions are called arguments.

  5. Console.log function is the common example. It’s used to print output values.

  6. Side effect means when you invoke a function and the output is visible on the screen immediately.

  7. Functions that produce side effect are, for example:

  • prompt or alert (with a dialog box);
  • console.log (writing text).

Instead, functions don’t produce side effect are, for example, all of the math functions used to calculate some results, for instance math.max e math.min.

  1. If a program contains more than one statement, codes are executed from top to bottom. The ability that a programmer should have is to control this flow in the best possible way.

  2. When a programmer wants to create a branching road, he has to use a conditional execution. It’s created with the if keyword in JS, so the code will be execute if, and only if, a certain condition holds.

  3. If, else, else if.

1 Like

An expression is code which outputs a value.

A binding is a named storage space that functions to hold a value.

An environment is the collection of all bindings with associate values that exist at that point in time.

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

A function example is: countNumbers(a, b) {
return a + b;
}
A side effect is anything that compromises the purity of a function

For example, a “pure function” is a function that maps its input value(s) into an output value function plus(x, y) { return x + y; } . A “side effect” is any effect other than that return value. ```
function plusWithSideEffects(x, y) { alert(“This is a side effect”); return x + y; } The alert portion of the code is the side effect.

Control flow is the way the program is executed. Javascript control flow is top to bottom like humans read a page.

With conditional execution, certain parts of the code are only executed if a certain condition is fulfilled, which enables the branching of the code.

A conditional expression is if

1 Like
  1. An expression is a piece of code that produces a value, also every value by itself inside the code is considered an expression. A program is a list of statements, while statements are made up of expressions.
  2. A binding is a connection or tentacle that usually points to a value. Bindings are established in JS by the code let followed by the name of the binding an operator and a value. Bindings can be either permanent throughout a program or new values can be reassigned to them at any step of the code.
  3. The environment is the set of bindings and their values that exist at a given time.
  4. A function is a piece of code enclosed in a value.
  5. console.log(), Math.max()
  6. A function produces one or more values, but some functions do additional things such as opening a dialogue box or modifying the screen. Those are considered side effects of the function.
  7. The prompt() function opens a dialogue box. The Math.min() function returns the lowest value of the parameters entered.
  8. The control flow of a program is the order in which statements are executed, which is from top to bottom.
  9. Conditional execution of parts of a program happens when the keyword if appears in the code. The commands within braces are only executed if the condition(s) set inside the brackets is/are true, otherwise they are skipped.
  10. see 9.
1 Like
  1. An expression is a fragment of code that produces a value.

  2. Bindings catch and hold values to programs.

  3. An environment 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. These values can be applied to run the wrapped program.

  5. Some examplse of a function are console.log, alert, and prompt.

  6. A side effect is a statement that affects or alters the world, in other words if the statement affects all the statements that come after it.

  7. An example of a function that produces a side effect is console.log because it will print something on to the screen. An example of a function that produces a value could be square which will calculate the square root of a given number.

  8. Control flow is when your program contains more than one statement, each statement will be executed from top to bottom.

  9. Conditional execution is when you want to create a branching of the road you are taking in the code and you want the program to execute the specific branch of the code you want.

  10. To invoke a conditional execution you can use the keywords if, Number.isNaN, else together with if.

1 Like

1. What is an expression?

An Expression is a piece of code which produce a value.

2. What is binding?

Refers to catching or holding a value without losing or changing to the old value. Binding is done by a specific keyword that will define the binding and it can start with any word, except numbers.

3. What is the environment?

The environment represents a collection of binding and its values.

4. What is a function?

A function refers to a piece of program that is wrapped in value, which can be used to run that particular program.

5. Give an example of a function.

Return - function at the end of the code will stop executing. This can compute and return value of the function.

6. What is the side effect?

A side effect stands for content that produces a value that could be displayed on the screen or it “could change the internal state of the machine and affect a statement that comes after it.” (//this statement is very hard to interpret in own words).

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

id=“age” value=“18”

function myFunction() {
var age, voteable;
age = Number(document.getElementById(“age”).value);
if (isNaN(age)) {
voteable = “Input is not a number”;
} else {
voteable = (age < 18) ? “Too young” : “Old enough”;
}
document.getElementById(“demo”).innerHTML = voteable;
}
9. What is a conditional execution?

Is creating a branching road for a program, which mean that the program takes the correct branch, given the current situation.

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

The conditional execution is created by implementing if or else keywords.

1 Like
  1. An expression is a piece of code that produces a value.
  2. A binding is a label that points to an address in memory that can be given a value.
  3. An environment is a set of bindings and their associated values in memory at any given time.
  4. A function is a block of code that is wrapped in a value.
  5. function displayName(){
    alert(“MyName”);
    };
  6. Displaying a value to the user is a side effect.
  7. function displayCube(){
    alert(cubeNumber()); // creates alert with value 27 returned from cubeNumber
    };
    function cubeNumber(){
    return 333; // produces value 27
    }
  8. Determining the order in which statements are executed.
  9. The control flow changes according to the results encountered by the program.
  10. A conditional statement is used to invoke conditional execution. If…else and switch are supported in Javascript.
1 Like
  1. What is an expression?

A fragment of code that produces a value is called

  1. What is a binding?
    bindings catch and hold values

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

  3. 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. For example, in a browser environment

  1. Give an example of a function.

prompt(“Enter passcode”);

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

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

(Math.max 2, 4 ));
(Math.min 2, 4 ) +100);

  1. What is control flow?
    is when statements are executed as if they are a story from top to bottom

  2. What is conditional execution?
    where the program takes the proper branch based on the situation at hand

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

the if keyword

1 Like

1. What is an expression?

An expression is a fragment of code that produces a value. Every value that is written is actually an expression. Expressions can also be written in parentheses and expressions can contain other expressions. Also expressions can be combained with operators.

2. What is a binding?

Bindings or variable is used to catch and hold values. The special word let indicates that a sentence is going to define a binding. It is followed by the name of the binding and, if we want to immediatly give it a value, by an = operator and an expression. After a binding has been defined, its name can be used as an expression.

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. In most cases in () or {}

5. Give an example of a function.

alert (“Hello to all!”)

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.

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

The function alert produces a site effect in the opposite console.log(math.max(2,4)) produces a value

8. What is control flow?

Control flow is how a program will execute the statements. Like reading a story from top to bottom.

9. What is conditional execution?

Not all programs are straight roads. Do this and then do this and then the next step. We may for example want to create a branching road , where the program takes the proper branch based on the situation. Do this but if a false take b.

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

A normal conditional execution needs only the if keyword but if it needs to be more complicated or with more options after the if comes the else and if more between they take the else if

1 Like
  1. Expression is a code that resolve into a value.
  2. Binding is a variable that contain info inside.
  3. Environment is a collection of binding.
  4. Function is a express wrapped in a value.
  5. alert(“alert is a fuction”)
  6. The Side Effect showing dialog box.
  7. Console.log (Math.max(2,4))
  8. Control Flow keeps the sequence of the sentence in the program.
  9. Conditional execution is when a program takes the proper branch based on the situation.
  10. if
1 Like

A fragment of code that produces a value, is called an expression. Every value that is written literally is an expression.

Bindings used to catch and hold values. They do not contain values; they grasp them, two bindings can refer to the same value.

The collection of bindings and their values that exist at the time, called environments.

Is a piece of program wrapped in a value.

alert (Hello World)

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

Side effect:
let theNumber = Number(prompt(“Pick a number”));
console.log("Your number is the square root of " +
theNumber * theNumber);

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

Is the order where function calls, instructions and statements are executed or evaluated when a program is running.

If we create a branching road, where the program takes the proper branch based on the situation at hand its a conditional execution.

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?
    • To catch and hold values, JavaScript provides a thing called a
    binding, or variable
  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 (named) in a value.
  5. Give an example of a function.
    • Alert() here a set of actions and values is invoked by stating a single value “alert()”
  6. 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. So, any action that can change the “state of the world” is a side effect. These are:
    • 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
    • Writing to the screen
    • Writing to a file
    • Writing to the network
    • Triggering any external process
    • Calling any other functions with side-effects
  7. Give an example of a function that produces a side effect and another function that produces a value.
    • .alert(“side effect”); Math.max(2,4);
  8. What is control flow?
    • The order of execution of statements.
  9. What is conditional execution?
    • A statement that allows a certain output if certain conditions stated with an IF statement are met.
  10. What kind of keyword do you need to use to invoke conditional execution?
    • IF
1 Like
  1. What is an expression?
    A fragment of code that produces a value is called an expression. A program can consist of several expressions. It is possible that an expression contains other expressions, which are nested inside. Even complex computations can be achieved with expressions, if the programmer constructs the structure of these expressions according to the problem to be solved.

  2. What is a binding?
    Bindings in JavaScript are used to catch and hold values. Bindings (or variables) are defined by using the var or let statement, the bindings name, the assignment operator ‘=’ and an expression. After a binding has been defined, its name can be used as an expression. The value of such an expression is the value the binding currently holds.

  3. What is an environment?
    The environment is the collection of bindings and their values that exist at a given time. It is not sufficient to keep track of all bindings and their values, because bindings also have a particular scope, which may be the whole program or a very small function only. Bindings (or variables) which are known in the whole program are called global bindings, while the other bindings are called local bindings, because they are only known in a limited part of the program, for example the funtion they are used in.

  4. What is a function?
    A function definition is a regular binding where the value of the binding is a function. It 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.

  5. Give an example of a function.
    function sum(summand1, summand2) {
    return summand1 + summand2;
    }

  6. What is a side effect?
    A function is said to have a side effect if it modifies some state variable value(s) outside its local environment, that is to say has an observable effect besides returning a value to the invoker of the operation. Example side effects include modifying a non-local variable, modifying a static local variable, modifying a mutable argument passed by reference, performing I/O or calling other side-effect functions.

  7. Give an example of a function that produces a side effect and another function that produces a value.
    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. What is control flow?
    Control flow is the order in which individual statements, instructions or function calls of a program are executed or evaluated.

  9. What is conditional execution?
    Depending on whether a programmer-specified boolean condition evaluates to true or false, the control flow can take different paths and perform different computations or actions.

  10. What kind of keyword do you need to use to invoke conditional execution?
    Conditional execution in JavaScript can be achieved by using the if statement. If the boolean condition evaluates to true, the statements in the first block (after the ‘if’) are executed. If the boolean condition evaluates to false, the statements in the second block (after the ‘else’) are executed. To assign a value to a binding depending on a boolean condition you can also use the ‘?’ operator instead of ‘if’ and ‘else’.

1 Like
  1. A fragment of code that produces a value
  2. Value being hodl :wink:
  3. Collection of bindings and their values
  4. A piece of program wrapped in a value
  5. Alerts
  6. Math.max - take numbers, gives back the highest
  7. console.log - value
    pompt - side effect
  8. Program executed from top to bottom
  9. Program takes the proper branch based on situation
  10. if
1 Like
  1. An Expression is fragment of code that produces a value.
  2. A binding holds the value of an expression until it is changed.
  3. An Environment is a collection of bindings and their values.
  4. A function is a piece of program wrapped in a value.
  5. “Prompt” is a function that displays a dialog box.
  6. A side effect is the result of a statement that can change the current state of something.
  7. A Dialog box is an example of a side effect of the function “prompt”.
  8. Control flow is the order of which your program executes its statements.
  9. A conditional execution is a separate direction the program can take if one direction is not applicable.
  10. To invoke a conditional execution you need the keywords “if” and " else"
1 Like