Binding, Functions and Control Flow - Reading Assignment


#162

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

What is a binding?
It is a statement that is used to catch and hold a value. It consists of a keyword followed by a name of the binding and, if you want to give it a value, followed by an = operator and an expression.

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

What is a function?
A function is a type of value with a piece of program wrapped in the value. E.g.:
The binding prompt
Holds a function
That shows a dialog box that asks for user input.
You call a function by putting parenthesis after an expression that produces a function value, e.g;
prompt();

Give an example of a function.
prompt(“Enter Password”);

What is a side effect?
When a statement changes the state of the machine in such a way that it will affect the statements that come after it, like 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();
Value: math.min(3,5);

What is control flow?
It is the sequence in which statements are executed.

What is conditional execution?
When we want to follow a branching pathway if a certain condition is met.

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


#163
  1. What is an expression?

An expression is a fragment of code which produces a value. An expression corresponds to a sentence fragment in the English language

  1. What is a binding?

Binding is the process of variables grasping values, which is important since a program can only access the values that it still has a hold on. We can use the ‘=’ operator so a variable can grab hold of a value. Once the variable has been defined (with any name, as long as it is not a reserved keyword) its name can be used as an expression.

  1. What is an environment?

An environment is a collection of variables and their values that exist at a given time in a program.

  1. What is a function?

A function is a piece of program wrapped in a value. All instructions inside of a function are executed from top to bottom. A function must be invoked and have arguments passed into it.

  1. Give an example of a function.

Some simple functions which produce side effects that we are familiar with when using browsers is the alert box, prompt and console.log functions. Functions which produce values such as math functions are very useful in programming too. As an example, Math.round rounds a numeric value to its nearest integer.

  1. What is a side effect?

A side effect is any application state change that is observable outside the called function. Some common side effect functions in JavaScript include alert, prompt & console.log.

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

An example of a function that produces a side effect would be the prompt() function. An example of a function that produces a value would be the Math.round() function.

  1. What is control flow?

Control flow is the order function calls, instructions & statements are executed or evaluated when a program is running. (Top to bottom!).

  1. What is conditional execution?

A conditional execution is when a control flow statement such as “if, else, and” are used to determine (based on Boolean values) what section of code is run in a program at a given time.

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

Conditional execution is written with the “if” keyword. The keyword “if” executes or skips a statement depending on the value of a Boolean expression.


#164
What is an expression?

Expression is a fragment of code that produces a value.

What is a binding?

In JavaScript, we use binding to catch and hold values. So that it is kind of a statement to keep an internal state.

What is an environment?

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

What is a function?

It is an expression that take inputs(arguments) and give an output.

Give an example of a function.

Math.max(2,6) or console.log(“example”).

What is a side effect?

Side effect is 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 > alert(“something”)
value > Math.max(1,5)

What is control flow?

When the program has two or more statements, statements are run as a controlled flow, top to bottom of that control flow. The running order of statements is called control flow.

What is conditional execution?

The program can be designed to use different statements on different conditions, this type of design can be called conditional execution.

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

“if” is the keyword that we need.


#165

hey guys,
I keep receiving this error.

Capture

Please, help to understand.


#166

I also get this type of issue. It says you have declared the constant already. You cannot declare it again. Change the name of the constant to greet or something and try again (e.g const greet = “Hola”:wink:
use var if you want to change it often.


#167
  1. Expression is a fragment of code that produces value
  2. Binding is a reference to a block of memory where information is stored
  3. Environment is a collection of bindings and their values that exist at a given time
  4. Function is a piece of program wrapped in a value, that can be called from the program

function exampleFunction() // example function declaration
{
alert(“hello from function”); //alert function call
}

  1. Side effect is any effect other than return value of called function.

function exampleFunction()
{
prompt(“Your name:”); // this creates a side effect
}

function exampleFunction(a,b) // example function declaration
{
return(a*b); //function returns value
}

  1. Control flow is an order in which statements are executed.
  2. Conditional execution happens when the next step is dependent on the result of conditional expression.

IF (condition == true)
{
executeCode();
}


#168

hey,

it says: redeclaration error

that means you’ve declared the greeting const before in the session.

Const is a type of variable that can not be re-declared (once you declare it it stays constant)

Solution:

use another const name
use var instead of const

Hope it hepls :slight_smile:


#169
  1. expression: a fragment of code that produces a value
  2. binding: a binding catches and holds values to variables and constants so that they can be uses as expressions
  3. enviroment: The collection of bindings and their given values at a given time in the program
  4. function: a piece of program wrapped in a value. It can be executed/called/invoked at any time
  5. example: math.max()
  6. 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. Example: alerts, prompts …
  7. function that produces a side effect: console.log(“hello”) --> hello
    function that produces a value: math.max(2,6); --> 6
  8. control flow: the order in which statements are executed. It allows you to dictate how your code runs under different conditions, or until a certain condition is met.
  9. conditional execution allows the program to take a different direction under a specific circumstance, or when a condition is met: If - than - else …
  10. if, else, else if…

#170

Aaa now I get it!
Thanks)):+1::blush:


#171
  1. A fragment of code that produces a value is called an expression.
  2. Binding is a way for a program to be kept internally within a computer. Binding is a method to reference a value when called upon.
  3. The collection of bindings and their values that exist at a given time is called
    the environment.
  4. A function is a piece of program wrapped in a value.
  5. prompt(“Enter passcode”);
  6. A statement stands on its own, so it amounts to something only if it affects the world. It 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.
  7. Prompt or log are examples of functions which result in side effect but Math.Max and Math.min produce value.
  8. The order in which statements are executed.
  9. Branching the control flow of a program based on a specific condition represents a conditional execution.
  10. If, else, while.

#172
  1. An expression is a part of a code that produce a value.

2.a binding points at a stored value. a variable. to make one, you can start the sentence with var, or let.

3.An environment is all of the bindings that are made in a program.

4.A function is a part of a program. A task/move, for the program to make.

5.alert(“This is a function that makes a little message pop up”)

6.A side effect is a change that affects the internal state of the machine in a way that will affect the statements that come after it. I.e a message-box.

7.Math.max(2,4); wil show the value 4.

  1. Control flow is how the program is read by the computer, top left to bottom right.

9.Conditional execution; You can set conditions for a function to (or not) execute. If conditions are met, it will runn a specific function, if not , it will run another.

  1. if() {…} else(){…} while(){…}

#173
  1. What is an expression?

An expression is a part of the code that produce a value.

  1. What is a binding?

A binding is an assignment of an expression to a variable.

  1. What is an environment?

An environment is a set of variables and their values.

  1. What is a function?

A function is a part of the program that is wrapped in a value. A function can return a value itself or produce side effects.

  1. Give an example of a function.

function timesTwo(x) {
return 2 * x;
}

  1. What is a side effect?

A side effect is any effect (changing variables, printing in the console, etc) other than returning a value that is trigger by executing a function.

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

Produces a side effect only:

function printName() {
console.log(“Thane”);
}

Produces a value only:

function timesTwo(x) {
return 2 * x;
}

  1. What is control flow?

A control flow is a program structure that allows for branching in the execution of the code depending on the environment.

  1. What is conditional execution?

A conditional execution is a block of code that is executed only if a set of conditions are found to be true.

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

The ‘if’ keyword is necessary to invoke conditional execution.


#174

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

2: What is a binding?
indings are like tentacles, they dont hold any information but they grasp them, to bindings can point to the same value.

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.

5: Give an example of a function.
alert and console.log

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

7: Give an example of a function that produces a side effect and another function that produces a value.
prompt(“Enter your name”);
value example
console.log(Math.max(2, 4));
it will output a value that is 4

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

9: What is conditional execution?
Conditional execution is when a block of code is executed only if a condition is met

10: What kind of keyword do you need to use to invoke conditional execution?
if, else and if else.


#175
  1. Anything that produces a value is an expression in JavaScript.
  2. To catch and hold 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. Such values can be applied
    in order to run the wrapped program.

var x = myFunction(4, 3); // Function is called, return value will end up in x

function myFunction(a, b) {
return a * b; // Function returns the product of a and b
}
6. Showing a dialog box or writing text to the screen is a side effect
7.console.log(Math.max(2, 4));
// → 4

function that return value:

console.log(Math.min(2, 4) + 100);
// → 102
8. When your program contains more than one statement, the statements are executed as if they are a story, from top to bottom.
9.We want to create a branching road, where the program takes the proper branch based on the situation at hand.

For example:

let num = Number(prompt(“Pick a number”));
if (num < 10) {
console.log(“Small”);
} else if (num < 100) {
console.log(“Medium”);
} else {
console.log(“Large”);
}
10. if statement and more such as if/else etc…


#176
  1. An expression is a fragment of code that produces a value.

  2. A binding catches and holds values.

  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. An example of a function is: prompt(“Enter passcode”);

  6. An example of a side effect is showing a dialogue box or writing text to the screen.

  7. An example of a function that produces a side effect: alert(“Hello world”); An example of a function that produces a value: console.log(Math.max(2,4));

  8. Control flow is the order in which the computer executes statements in a script.

  9. Conditional execution is when code is executed if and only if, certain conditions hold.

  10. To invoke conditional execution, the word if is used.


#177

1, An expression is a fragment of code produced as a value.
2, Binding/Variable is created to catch and hold values.
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.
5, alert(“hello universe”);
6, A side effect is showing a dialog or writing text on screen.
7, prompt(“collective consciousness”);
a=6; b=9 console.log(a+a*b);
60
8, Control flow is the order the execute the code. It is executed from top to bottom in JavaScript.
9, When the program is not straight forward, Sometimes we use the proper branch route based on the situation at hand. This is called Conditional execution.
10, if


#178
  1. An expression is a fragment of code that create a value and we can build expressions to describe arbitrarily computations.
  2. Binding is used in Javascript to catch and hold values produced by two or more value
  3. Environment is a collection of binding and their values exist in a given time
  4. Function is a piece of program wrapped in a value and the values can be applied for running wrapped program
  5. Prompt (“Enter Username”);
  6. Side is any application state change that is observable outside the called function other than its return value
  7. Prompt (“Enter Username”) & console.log(Math. Min (3, 8)
  8. Control flow is when the program contains more than one statement when the statement are executed like a story from top to bottom.
  9. Conditional execution is when the program will take and execute the proper branch
  10. If, else, else if

#179
  1. A fragment of code that produces a value.

  2. A thing to catch and hold values.

  3. The collection of bindings and their values that exists at a given time.

  4. A piece of program wrapped in a value.

  5. prompt(“Enter passcode”);

  6. A change of the internal state of the machine that affects statements that come after it.

  7. Side effect: prompt(“Enter passcode”);
    Return value: console.log(Math.max(2,4));

  8. Statements are executed from top to bottom.

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

  10. if, else, while, do


#180
  1. What is an expression?
    In JavaScript language, an expression is any valid set of literals, operators, variables, and expressions that evaluates to a single value. The value may be a number, a string, or logical value.

  2. What is a binding?
    Binding generally refers to a mapping of one thing to another. In the context of software libraries, bindings are wrapper libraries that bridge two programming languages, so that a library written for one language can be used in another language. Bind in JavaScript is a method and the moment at which binding occurs is called “bind time” or “link time”.

  3. What is an environment?
    In computer program and software product development, the development environment is the set of process and programming tools used to create the program or software product.

  4. What is a function?
    A function is a segment that groups a number of program statements to perform specific task. It can be either a user defined function or a library function.

  5. Give an example of a function?
    For example, programming functions might take as input any integer or number. The function might create output by multiplying the input time two. Therefore, the output of the function would be double its input.

  6. What is a side effect?
    A side effect simply refers to the modification of some kind of state such as when a procedure changes a variable from outside its range.

  7. Give an example of a function that produces a side effect and another function that produces a value.
    For example, a) changing the value to a variable; b) writing some data to disk; and c) enabling or disabling a button in the User Interface.

  8. What is control flow?
    Control flow is the order in which individual statements, instructions or function calls of an imperative program are executed or evaluated.

  9. What is conditional execution?
    Conditional execution is a statement that consists of a header and a body. It is a feature of a programming language which perform a specified computation or action depending on whether a programmer specified a Boolean condition evaluates true or false.

  10. What kind of keyword do you need to use to invoke conditional execution?
    i) The simplest form is the if statement which has the general form:
    if Boolean expressions:
    statements
    ii) The if else statement


#181
  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:
    let caught = 5 * 5;
    
  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 JavaScript function is a block of code designed to perform a particular task.
    For example:

                          function myFunction(p1, p2) {
                          return p1 * p2;   
    
  5. Give an example of a function.
    function myFunction(p1, p2) {
    return p1 * p2;

  6. What is a side effect?
    A side effect by virtual of its name is something that occurs that’s indirect as a relationship of an action
    that you took.

  7. Give an example of a function that produces a side effect and another function that produces a value.
    console.log(Math.max(5, 10));
    // → 10

console.log(Math.min(4, 8) + 100);
// → 104

  1. What is control flow?
    A control structure additionally contains another statement which is executed under specified
    conditions, by modification and/or validation of the environment

  2. 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. This is called conditional execution.

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