Binding, Functions and Control Flow - Reading Assignment

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

What is a binding?
A statement that allows you to hold values.

What is an environment?
The collection of bindings and their values that exist at a given time. This environment is never empty and for example
allows you to interact with the currently loaded website in your browser.

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

Give an example of a function.
prompt

What is a side effect?
Changes that a statement makes that will affect the statements that come after it.

Give an example of a function that produces a side effect and another function that produces a value.
Side effect:
prompt(‘Enter Code’);

Value:

let age = prompt(“What’s your age?”)

if (age >= 18) {
console.log(‘Adult’) }
else {
console.log(‘Child’}

What is control flow?
Not sure on this one, but I think it’s the way your computer reads your program. In this case it’s from left to right, top to bottom.

What is conditional execution?
Making a program make decisions based on the conditions that you set.

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

1 Like
  1. What is an expression?
    a piece of code that creates a value.
  2. What is a binding?
    a binding holds variable values
  3. What is an environment?
    a 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.
    inputting a password into a prompt or entering a comment into a website using an extention.
  6. What is a side effect?
    showing a dialog box or entering text.
  7. Give an example of a function that produces a side effect and another function that produces a value.
    a side effect would be a password being entered into a console or to gain access to a site. a value would be like posting a comment on a website.
  8. What is control flow?
    when your code has more than 1 statement. so it reads and executes from top to bottom.
  9. What is conditional execution?
    its when your code branches into 2 separate options based on input. if else.
  10. What kind of keyword do you need to use to invoke conditional execution?
    IF
1 Like
  1. An expression is a fragment of code that produces a value, every value that is stated such a number or string is an expression. Expressions can contain other expressions which gives way to complex computation.

  2. A binding catches and holds values, they keep and internal state. Once a binding is defined it can be used as an expression to be fetched later.

  3. The environment is the collection of bindings and their assigned values within a program.

  4. A function is a piece of program wrapped in a value. These values are invoked to run the wrapped program.

  5. The prompt function invoked in a browser environment will show a dialog box asking for user input.

  6. When your program shows a dialog box or writing text it is called a side effect.

  7. The (Math.max) function produces a value.
    The prompt() function produces a side effect.

  8. The order in which a program executes multiple statements.

  9. When a program executes a certain order based on a certain condition.

  10. The keyword to invoke conditional execution is the “if” statement.

1 Like
  1. What is an expression?
    An expression is a fragment of code that produces a value - ‘23’ is an expression, as is the word ‘pineapple’

  2. What is a binding?
    A binding is a variable which is used to catch and hold values - for example let caught = 5 * 5;
    The keyword let indicates that this sentence is going to define a binding - it is followed by the name of the binding, and by an = operator and an expression

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

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

  5. Give an example of a function.
    In a browser environment, the binding prompt holds a function that shows a dialogue box asking for user input

prompt(“Enter passcode”);

  1. What is a side effect?
    A side effect is any effect other than a return value - showing a dialogue box or writing text to the screen is a side effect. Basically you are changing the internal state of the machine in some way that affects the statement proceeding it

  2. Give an example of a function that produces a side effect and another function that produces a value.
    Side effect example - prompt(“Name”);
    Value Example - Math.max(2,4);

  3. What is control flow?
    The order that instructions, statements, or functions are executed - the code is read from top to bottom unless there are some instructions or statements which change that control flow

  4. What is conditional execution?
    Conditional Execution is a branching path where the program chooses which branch to take based on a Boolean condition

  5. What kind of keyword do you need to use to invoke conditional execution?
    The ‘if’ keyword

Cheers :woman_cartwheeling:

1 Like
  1. every value that is written literally is an expression.
  2. to catch and hold values. bindings are tentacles rather than boxes, they grasp values.
  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 ("")
  6. showing a dialog box or writing text to the screen
  7. prompt("") & math.max
    8.the control flow is the order in which a program executes its statements
    9.where the program takes the proper branch based on the situation at hand.
  8. if
1 Like
  1. An expression is a fragment of code producing a value.

  2. A binding or variable is a collection of values.

  3. An environment is a collection of bindings with values at a given time.

  4. A function is a set of instructions bundled together to achieve an outcome from its inputs.

  5. example: prompt(“enter passcode”);

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

  7. side effect example --> prompt(“enter password”);
    Value example --> console.log(Math.min(2,4));
    The output value will be 2

  8. Control flow is the order in which coding is executed, from top to bottom and then evaluated.

  9. Conditional execution: A comand is only executed if a certain condition if fulfilled.

  10. if

1 Like

1.a fragment of code that produces a value is called an expression.
2. a binding or varible allows u to catch or hold values.
3. the collection of bindings and their values that exist at a given time is called the enviornment.
4.a function is a piece of program wrapped in a value.
5. prompt (“Enter passcode”);
6. is a showing a dialog box or written text on a screen.
7. wouldnt question 5 answer be a side effect. and console.log(Math.max(2, 4));
8. control flow would be the direction you want to program to execute.
9.conditional execution is created by the if command which i think is NaN.
10. Number.isNaN

1 Like

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

that is written literally (such as 22 or “psychoanalysis”) is an expression.

What is a binding?

To catch and hold values, JavaScript provides a thing called a

binding, or variable

What is an environment?

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

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

Give an example of a function.

A function can be a dialog box that prompts for a passcode

What is a side effect? Showing a dialog box or writing a 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. Math.max takes any amount of number arguments and gives back the greatest number which produces a side effect. The function also produces a value which is 4

Console.log (Math.max(2,4));
// -> 4

What is control flow? A control flow is a program which contains more than one statement, the statements are executed as if they are a story, from top to bottom.

What is conditional execution? A conditional execution is when not all programs are straight roads

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. What is an expression? » An Expression is a fragment of code the produces a Value.
  2. What is a binding? » A binding or variable makes it so that JavaScript catches and holds onto a value. It sets a value under a certain name or symbol which can then be used in functions, expressions etc.
  3. What is an environment? » The Environment is the collection of all Bindings and their values that exist at any given time.
  4. What is a function? » A function is a piece of program wrapped in a value. This value can be called in order to run the wrapped program.
  5. Give an example of a function. » prompt. In a browser, prompt, holds a function that shows a dialogue box, asking for user input.
  6. What is a side effect? » A statement which changes something; be it a pop-up with text, a dialogue box requesting input or a statement changing the internal state of the machine/program so that it affects 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. » prompt is a function that has a side effect. And console.log is a function that produces a value.
  8. What is control flow? » When a program contains more then one statement, the statements are executed in order from top to bottom. This is the Control Flow, making sure that the statements are executed in the order as intended.
  9. What is conditional execution? » Conditional Execution is a program which follows/takes a certain branch/option based on the situation or the input at hand.
  10. What kind of keyword do you need to use to invoke conditional execution? if and else are used to invoke Conditional Execution.
1 Like
  1. An expression is any value written literally between parentheses.

  2. A binding like “let” is used to define a variable.

  3. An environment is a collection of bindings and their values, that load up automatically when you load up a text editor application to code.

  4. Functions are expression wrapped in a value. It can executed by calling it.

  5. Console.log ("") is a function, when you can put text between the parentheses, you create an expression and function.

  6. A side effect is a function that produces an expression, just like the answer for question number 5.

  7. Console.log produces a side effect and Math.min produces a value.

  8. Control flow is simply the order that code and statements are evaluated.

  9. Not all programs contain a single possible outcome, instead there can be multiple possibility’s, the program will choose based off of its best possible result at hand, that is how conditional execution works.

  10. Conditional Execution is created with the “if” keyword in Java Script.

1 Like
  1. An expression is a fragment of code that leads to producing a value. Any value that can be written literally whether as a number or string can be considered an expression.

  2. Binding is the method by which Javascript catches and holds values. Once a binding has been defined it’s name can be used as an expression. The value of that expression is the value the binding currently holds. A binding can consist of a definition followed by a name followed by a value.

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

  4. Functions are pieces of program code that are wrapped in a value. Such values can be applied to run the wrapped program.

  5. A great example of a simple function is the prompt binding. It holds a function that causes a pop-up to appear on a web browser asking for user input. The prompt function uses the string we provide as the display text of the pop-up dialog.

prompt(“What is your username?”);

  1. A side effect is what we call the change when a statement leads to impacting/changing the world. This “changing the world” could be a matter of displaying something on the users screen or changing the internal state of a machine which will thus affect any statements that follow it.

  2. An example of a function that produces a side effect is: prompt()
    An example of a function that produces a value is: console.log()

  3. Control flow is in reference to programs containing more than one statement, where the statements are executed in a top-to-bottom manner, almost as if following a story.

  4. Conditional execution is in reference to programs that have the ability to branch into multiple different options/roads, based on the situation/user input.

  5. In Javascript conditional execution can be done by using the “if” and “else” keywords.

1 Like

1: a piece of code that produces a value
2: a binding aka variable, effectively holds an value. But it can be changed
3: a collection of the binding and their values
4: a function performs a specific action in the program
5: alert(‘this is text’)
6: showing a dialog box or writing text on the screen
7: a value function, console.log(Math.max(2, 4));
a alert function would be, prompt(‘insert text’)
8: control flow is the order in which the code runs through
9: a program that will only execute if certain things are fulfilled
10: if, else, etc


1 Like
  1. What is an expression?
    A snippet of code that evaluates to a value.

Arithmetic Expression Example.
8; is a numeric expression value of 8
Or
4+4 is also numeric expression value of 8

String Expression Example below that evaluates to a string
‘good bye’;
‘good’ + ‘bye’; evaluates to a the string ‘good bye’

  1. What is a binding?

A binding keeps and internal state. It will effect the entire program. In other words, A binding assigns values to a variable.

Example below

let sum = 5+6;
(5+6 defines the binding)

let sum2 = 10+10;
(10+10 defines the binding)

console.log(sum+sum2);

The answer 31 is the addition of sum(binding) plus sum2(binding).

  1. What is an environment?
    An Environment is a collection of bindings and values at the exist in a given time. Is the entire program and its instructions?

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

  3. Give an example of a function

  • prompt (“help”)
  • Binding promp makes ‘help’ come up in a dialog box asking for input.
  1. What is a side effect?

A Side Effect is a result of when a Pure Function is affected by inputs that alter the state of a Pure Function.

JS programmers can use Side Effects to manipulate code that influences outcomes.

JS Programmers must be aware when Pure Functions are influenced by an input that creates the Side Effect. So, the programmer can create reliable code.

Avoid unexpected Side Effects.

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

A random function that produces a side effect is time(). This is because time is constantly changing. So the outcome will always be uncertain.

An example of a function that produces a value is sqrt(). This will always have the same result—a value of a number that is squared.

  1. What is control flow?

Control flow is the order the computer execute a command in the script created by the JS programmer.

  1. What is conditional execution?

Conditional execution is the decides if the core of the program will execute command.
An example would be if we take a block of code and it executes if a condition is met.

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

“If” or “Else”

“If” statements: where if a condition is true, it is used to specify execution for a block of code.
“Else” statements: if the same condition is false, it specifies the execution for another block of code.

1 Like

An expression is any piece of code that expresses a value.
JavaScript expressions are commonly classified into two types and five categories. Let’s learn more about these classifications below.

There are two types of JavaScript expressions:
(i) assignment - example: x = 3
(ii) non-assignment - example: 3 + 7

The five categories of JavaScript expressions are:-
(i) arithmetic - examples:
          z = 5 + 2
          10
          5 + 2
(ii) string - examples:
          “Hello” + " " + “World”
          “1234”
(iii) logical - examples:
          7 > 100
          100 > 7
          true
(iv) primary - examples:
          “Hello”         // String literal
          1234           // Number literal
          class           // class keyword
          function       // function keyword
          undefined     // undefined value
(v) left-hand side - example:
          x = 100 + 30

A binding is the attachment of a name (also called an identifier) to an entity.

A runtime environment is where your program will be executed. JavaScript code may be executed in one of two runtime environments:

  1. a browser’s runtime environment
  2. the Node runtime environment

In each of these environments, different data values and functions are available, and these differences help distinguish front-end applications from back-end applications.

  • Front-end JavaScript applications are executed in a browser’s runtime environment and have access to the window object.
  • Back-end JavaScript applications are executed in the Node runtime environment and have access to the file system, databases, and networks attached to the server.

A function is a block of code that performs some tasks or does some computation and then returns the result to the user.

function calcAddition(number1, number2)

{

return number1 + number2;

}

In functional programming, side effects are any state change that can be seen outside of a function call, with the exception of the function return value. According to the rules of functional programming, functions are not allowed to modify any states outside of the function. If the function modifies a state, intentionally or unintentionally, this is considered a side effect because it breaks the tenets of functional programming.

var bob = {
    name: “bob”,
    smiling: false
};

function kittenHug(person) {
    person.smiling = true;
    return (person.name + “was hugged by a kitten”);
}

kittenHug(bob);

Control flow in JavaScript is how your computer runs code from top to bottom. It starts from the first line and ends at the last line unless it hits any statement that changes the control flow of the program such as loops, conditionals, or functions.

Conditional execution is the execution of code to perform different actions based on different conditions.
We can use conditional statements in our code to do this.

In JavaScript we have the following conditional statements:

  • We use if to specify a block of code to be executed if a specified condition is true.
  • We use else to specify a block of code to be executed if the same condition is false.
  • We use else if to specify a new condition to test if the first condition is false.
  • We use switch to specify many alternative blocks of code to be executed.
2 Likes

1: code that produces a value=expression ie. var a= happy
value a creates the happy expression
2.binding is the way the program stores info and can regurgitate later
3: there is local environment which is the program created (bindings) and such which exist in this sequence engaged upon , and then there is the glogal environment ie the browser lang/bindings already in existence predetermined.
4.piece of program that was impregnated by a value.
5.var emotion= (“booooooooo”)
alert(emotion)
6.showing a user input box
7.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.
8.up to down logic meaning even if at alater point in the the script a value is changed the previous ‘‘printings’’ wont change
9.if else

1 Like
  1. What is an expression?

A fragment of code that produces a value.

  1. What is a binding?

A way to catch and hold values. Also referred to as variable. “Let” is a binding word. Bindings are like tentacles, they grasp boxes.

  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. These values can be applied in order to run the wrapped program. Executing a function is called invoking it, calling it or applying it.

  1. Give an example of a function.

Prompt (" Enter Password");

  1. What is a side effect?

When a statement changes the internal state of a machine in a way that affects the statements that come after it. Showing a dialog box or writing text to the screen etc.

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

Value: math.max function

Side effect: console.log or Prompt functions

  1. What is control flow?

When a program contains more than one statement, the statements are executed as if they are a story, from top to bottom. Can be a straight line or conditional execution.

  1. What is conditional execution?

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

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

Can be created using the key word “If”

“Else” refers to the alternative choices after the “If” function.

1 Like

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

What is a binding? To catch and hold values, JavaScript provides a thing called a binding, or variable.

What is an environment? The collection of bindings and their values that exist at a given time is called 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? An expression could display something on the screen—that counts as changing the world—or it could change the internal state of the machine in a way that will affect the statements that come after it. These changes are called side effects. 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. console.log(Math.max(2, 4)); // → 4 console.log(Math.min(2, 4) + 100); // → 102

What is control flow? When your program contains more than one statement, the statements are executed as if they are a story, from top to bottom.

What is conditional execution? Not all programs are straight roads. We may, for example, want to create a branching road, 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

1. What is an expression?
A fragment of code that produces a value, no matter how simple in its build. Simply declaring a value, with no further interaction with that value, is seen as an expression.

2. What is a binding?
To put it simply, a binding is a way to store a value for future use. It uses the keyword let to announce it, which is followed by the name of the binding and a value - although the value doesn’t necessarily need to be declared at this point.

3. What is an environment?
The environment is the collection of all the bindings in use at a given time, as well as their values. The environment is never empty, as there are bindings loaded by default which are needed by default or in order to interact with the used system.

4. What is a function?
A function is a piece of program wrapped in a value. I’m guessing that it can also be seen as the inverse - a value wrapping a piece of code. We can use that value to easily call that piece of code. A function can also be given values, which are called arguments.

5. Give an example of a function.
The best example of a function is console.log, as this is used a lot both in the book and tutorials, but more importantly in the console. Interestingly, the console part refers to a function, while the log part is a way to refer to that specific property of the console function.

6. What is a side effect?
A side effect is a type of a function result which either changes the system in some way or has a tangible interaction inside the environment (like displaying a dialog box). The other type of function result is a value, which does not produce a tangible result inside the environment.

7. Give an example of a function that produces a side effect and another function that produces a value.
The prompt function has a side effect type of result. The Math.max and Math.min functions have a value type of result. I find it a bit unclear if the console.log function is a side effect type, as it does produce a tangible effect inside the console. Maybe someone can clarify this :slight_smile:

8. What is control flow?
Control flow is the order in which the code is executed. By default this is from top to bottom in sequential order.

9. What is conditional execution?
Building on control flow, conditional execution is a way to control the execution of the code based on given conditions. By default this is a straight flow from top to bottom. With conditional execution however, code will only be executed if the given conditions are met.

10. What kind of keyword do you need to use to invoke conditional execution?
The main keyword needed here is if, which will follow or not follow up a path based on a Boolean representation of the given argument value. However, if is closely intertwined with the else keyword, which offers the alternative path, in case the Boolean value from the if argument is false.