Binding, Functions and Control Flow - Reading Assignment

console.log(Math.max(16,24));


// 24
thank you

1 Like
  1. Expression is a chunk of code, which gives a value.
  2. A binding is some kind of tag directing from variable to a memory location, where some value is physically stored.
  3. An environment is all the values and bindings existing in the program at the current moment.
  4. Function is a piece of code wrapped in value. It takes an inputs, does some computation and provides an output.
  5. function MysimlpeFunction (num1, num2)
    { return num1+num2 }
  6. I might be wrong, but as I understand, a side effect happens when a code or statement has effect on other piece of code or statement.
  7. side effect:
    let theNumber = Number(prompt(“Pick a number”));
    console.log("Your number is the square root of " +
    theNumber * theNumber);
    Value:
    let ten = 10; console.log(ten * ten);
  8. It’s an order how the program code is executed. A code is executed from top to bottom by reading instructions one by one.
  9. Conditional executions gives a possibility to modify an order how a code is executed.
  10. if, else, else if, while, loop.
1 Like

A: A fragment of code that produces a value

A: A way to catch and hold values in javascript such as keeping an internal state or remembering things

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

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

A: Making a value work with a function is like when you are lookig for a certain product on amazon you ask the “search” bar to find a “carseat”

A: Showing a dialog box or writing text to the screen

A: wWhen looking for a value of a car you might look for the price range you can afford based on how much you have so the min. amount or the max. would be based off of the amount you have “$5000”
min $500 max $5000 my budget is $3000

A:When your program contains more than one statement, the statements are
executed as if they are a story, from top to bottom

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

A: The if keyword executes or skips a statement depending on the value of
a Boolean expression

1 Like

Thanks for let me know all my miss-understandings. This concepts are a bit abstract for me, can you give me a very kinder-garden example of it.

I think I understand that this part of the code is not showing what i intent to ? So there is no side effect.

So I get that a function is a pice of code enclosing in a value.

Thanks for your help
have a good one !

1 Like
  1. A fragment of code that produces a value is called an expression.
  2. A binding catches and holds JavaScript 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. For example, in a browser, there are functions to interact with the
    currently loaded website and to read mouse and keyboard input.
  6. Showing a dialog box or writing text to the screen is a side effect.
  7. Example Side Effect: The function Math.max takes any amount of number arguments and gives
    back the greatest.
    console.log(Math.max(2, 4));
    // → 4
    Example value function:
    console.log(Math.min(2, 4) + 100);
    // → 102
  8. When a program contains more than one statement, the statements are
    executed from top to bottom.
  9. Some code is required to be executed if, and only if, a certain condition
    holds.
  10. The if keyword.
1 Like
    1. A fragment of code that produces a value.
  1. A binding is a statement that references a value. eg, let lunchMoney = 100;
  2. “The collection of bindings and their values that exist at a given time is called the environment.”
  3. A piece of program that is wrapped in a value.
  4. Math.min() or prompt()
  5. A side effect could be something that the browser displays as a result of a function.
  6. prompt() and console.log(Math.min(2,4) + 100);
  7. It is the flow or direction in which statements are executed.
  8. Instructions of how what a program needs to do if presented with certain conditions.
  9. You need to the ‘if’ keyword in order to make a conditional statement.
1 Like
  1. What is an expression?

Any piece of code that produces a value, including values.

  1. What is a binding?

Similar to a variable, a binding binds a value to itself. It effectively stores that value within itself, acting as a reference to said value.

  1. What is an environment?

An environment is a collection of all bindings and their values. Even if no specific binding has been created, there is still a collection of default/standard bindings found in an environment.

  1. What is a function?

A function is a procedure used to execute code, or find a value, using the instructions provided within the function.

  1. Give an example of a function?

function sum(a,b) {return a + b};

  1. What is a side effect?

A side effect is an observable effect, besides a returned value, that occurs when executing programming instructions. Example: a pop up window.

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

a. prompt(“Enter Password”) or alert(“wazzup”)
b. Math.max(2,5,8,14,35);

  1. What is control flow?

The order in which statements are executed. They are executed in the chronological order in which they are written.

  1. What is conditional execution?

With conditional executions certain parameters need to be met before the code is executed. Example: only if this happens, execute the code.

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

if

1 Like
  1. An expression is anything that produces a value.
  2. It is a bindings job to catch and remember a value so that it can be referenced later. It does not contain the value, but simply holds a defined value until it is changed.
  3. An environment is a collection of bindings and their values in existence.
  4. A function is a piece of program wrapped in a value, meaning that the piece of program is only executed once a value has been applied.
  5. let firstName = String(prompt(“What is your first name”));
    console.log("My name is " + firstName);
  6. A side effect is anything that happens as a result of a function.
  7. A function that produces a side effect would be one that returns a dialogue box. A function that produces a value could be one that returns number in the console.
  8. Control flow refers to the sequential order that statements are executed in when there is more than one statement.
  9. Conditional execution is when a piece of code is only executed on the condition that a certain value is returned.
  10. In order to invoke a conditional execution, you can use the keyword ‘if’, which means that a certain piece of code is only executed if that value is returned.
1 Like

Hi @kmilo_Mart!
Yes, they are abstract… I’ll do my best…

Exactly right…and the functions that create these side effects are:

alert("Print my side effect in the pop-up box!");

console.log("Display my side effect in the console!");

Exactly right…

function plus(x, y) {
   return x + y;
}

This function returns the sum of x + y (a value) to wherever IN THE PROGRAM the function was called from. It is not something that happens OUTSIDE OF THE PROGRAM (like printing to the console).

Yes…this description of a function is pretty abstract to be honest, but by a piece of code (or “mini-program”) enclosed within a value I think the author means that when the function executes it returns a value, so in the end it equates to a value… at least that’s how I understand this definition! :sweat_smile:
To be honest, it’s probably easier first of all to define these different programming concepts with an actual visual example of the code. Then when you can visualise that from memory, you can start to think about what the code really achieves.

I hope that makes things even clearer! :smiley:

1 Like

Hi @Bifin!

Just a couple of things to clarify, really…

The actual function that produces a value is Math.max(2, 4)
The console.log() that it’s wrapped in, is a function that produces a side effect, the side effect being printing the highest number (4) to the console.

Here, the actual function that produces a value is Math.min(2, 4)
The console.log( + 100) that it’s wrapped in, is the function that produces a side effect, the side effect being printing the lowest number + 100 (102) to the console.

1 Like
  1. What is an expression?
    It is any fragment of code that results in a value.
  2. What is a binding?
    It is when a value or string is set to a variable, which enables the programmer to recall the it in anywhere in the code once it has been set.
  3. What is an environment?
    It is all the bindings made in the within the program.
  4. What is a function?
    It is a piece of program encapsulated in a value.
  5. Give an example of a function.
function mult(a,b){  
   return a*b;
}
console.log(mult(2,2));
//4

  1. What is a side effect?
    A function that produces an expression and returns that specific value.
  2. Give an example of a function that produces a side effect and another function that produces a value.
//side effect
alert("hello")
//function
   return a*b;
}
console.log(mult(2,2));
//4
  1. What is control flow?
    It is the order in which lines of code are executed.
  2. What is conditional execution?
    It is the point at which the programs makes decision based on the conditions given.
  3. What kind of keyword do you need to use to invoke conditional execution?
for(){
}
1 Like
  1. Expression is a piece of code that returns value.
  2. Binding catches and hold values.
  3. An environment is all of the bindings that have been made within a program.
  4. A function is a piece of program wrapped in a value .
  5. alert(“hello”);
  6. A side effect is an observable change in the state of the application.
  7. prompt(“abc”);
    console.log(“hello”)
  8. The order in which the code is executed.
  9. When the order of the execution is branched in multiple paths.
  10. if
1 Like
  1. What is an expression? “A fragment of code that produces a value”
  2. What is a binding? They are used to catch and hold new values
  3. What is an environment? The complex of bindings and their values
  4. What is a function? The piece of program wrapped in a value
  5. Give an example of a function. prompt(“Enter passcode”);
  6. What is a side effect? The result of a function that is showing a dialog box or writing text on the screen
  7. Give an example of a function that produces a side effect and another function that produces a value.

Side effect prompt(“Enter passcode”);

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

// → 4

  1. What is control flow? The order on which computer is executing the program, from first line to last one
  2. What is conditional execution? When the execution of a command is depending on a certain condition
  3. What kind of keyword do you need to use to invoke conditional execution? IF keyword
1 Like
  1. A fragment of code that produces a value is called an expression.

  2. Binding catches and holds values

  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. let red = 16;
    console.log(“red”);

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

  7. console.log(Math.max(2, 4, 6, 8, 10));

    alert(“Hello world”);

  8. When your program contains more than one statement, the statements are
    executed as if they are a story, from top to bottom.

  9. If we create a code that is branched depending on the condition that code will be an example of a conditional execution.

  10. if

1 Like

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

Hello sir, a for is not exactly a conditional statement. The for statement creates a loop that consists of three optional expressions, enclosed in parentheses and separated by semicolons, followed by a statement (usually a block statement) to be executed in the loop.

Conditional statements control behavior in JavaScript and determine whether or not pieces of code can run.

Here a simple website that can help you to understand it even better: JAVASCRIPT CONDITIONALS

Hope this gives you a clear view of the subject, keep learning! :slight_smile:

If you have any doubt, please let us know so we can help you!

Carlos Z.

1 Like
  1. What is an expression?
    An expression is a fragment of code that produces a value. It corresponds to a sentence fragment. It ends with a semi-colon.

  2. What is a binding?
    Binding is also called variable.

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

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

  5. Give an example of a function.
    Example: alert(“Greetings”);

  6. What is a side effect?
    Side effects are the internal changes that affect 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.
    Example of value: math.max produces a value
    Example of a function with side effect
    “Confirm” function produces an extra window

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

  9. What is conditional execution?
    A conditional execution is a control flow where we choose between two different routes based on a Boolean value. It’s a “if
    Example: var age= 17;
    If (age<18)
    Console.log(“You are an adult”);

  10. What kind of keyword do you need to use to invoke conditional execution?
    If, else, switch

1 Like
  1. An expression is any kind of code that results in a value.

  2. A binding or variable catches and holds values.

  3. The collection of bindings and their values is called the environment.

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

  5. prompt(“Enter passcode”);

  6. A side effect is where a functions does something other than return a value.

  7. prompt(“Enter passcode”); prompts dialogue box
    console.log(Math.max2, 4); produces a value

  8. The order in which statements are executed, left -> right, top -> bottom.

  9. When the program takes the proper branch based on the situation at hand.

  10. If

1 Like

ohh that makes sense, I appreciate it!

2 Likes

Some really good answers here, @Emmerich! I can see you’ve really understood the concepts as you’ve described things using your own words.

Keep up the great work! :muscle:

1 Like
1. What is an expression?

Anything that produces a value is an expression in JavaScript.

2. What is a binding?

To catch and hold values, JavaScript provides a thing called a binding, or variable. 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.

4. What is a function?

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

5. Give an example of a function.

prompt(“Type a value”);

6. What is a side effect?

Showing a dialog box, writing text to the screen or change the internal state of the machine in a way that will affect the statements that come after it. A side effect is any application state change that is observable outside the called function other than its return value.

7. Give an example of a function that produces a side effect and another function that produces a value.
  • alert(“Bitcoin is pumping”); - produces a side effect

  • Math.max(x , y); - produces a value

    8. What is control flow?
    

When a program contains more than one statement, control flow is the order in which the computer will execute the statements in the script.

9. What is conditional execution?

Conditional execution creates a branching road, where the program takes the proper branch based on certain conditions, assisting in decision making.

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

We can use the if keyword to invoke a conditional execution, and together with else, to create two separate, alternative execution paths.

1 Like