What is an expression?
An expression is any arrangement of symbols, that produces a value. It can be for example a number, string, or a result of complex arrangement of values, operators and expressions.
What is binding?
Binding is a variable, that is declared with the keyword let. It can be tagged to any value. It can also be changed to point to another value at any time. Keywords var and const are also used to define bindings. A binding defined with const can’t be changed.
What is an environment?
An environment is collection of bindings and values that exist at a given time.
What is a function?
Function is a set of statements that performs some task or calculates and returns a value. Function is also a value.
Give an example of a function.
console.log(“hello”);
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.
Give an example of a function that produces a side effect and another function that produces a value.
console.log(100*200), Math.pow(8,3)
What is control flow?
When a program contains several statements, they are executed in certain order. This is called control flow.
What is conditional execution?
Parts of the code might be executed only if a specific set of conditions are true. In other words, parts of the code are executed conditionally.
What kind of keyword do you need to use to invoke conditional execution?
It can be done with keywords if, else if, else. There are also other ways to do it. The conditions in loop statements determine how many times the code is executed. Also switch, case can be used.
An expression can be either a value or a mathematical operation or function of one or multiple values. It can also be an expression of an expression.
A binding is how a program creates and maintains an internal state, with clearly defined variables. The functions “let” and “var” can be used for that. However, the internal state can be changed again in the future, so the binding itself is not always static. It works more like a tether, tethering it to a specific value. On the other hand, using “const” creates a constant variable that stays the same forever.
An environment is a collection of the bindings and values inside the program, maintaining its internal state. A program always starts out with things like functions and syntax needed to run itself. The programmer can define more bindings in the program as needed.
A fuction is a program either already provided in the default environment, or one that can be defined by the programmer. It makes doing a complex task easier as the operations of the function are already clearly defined and ready to use.
prompt(), console.log(), alert()
A side effect is an expression or function that modifies the state of something outside its scope, such as one function redefining a variable outside itself, or the program giving an output into the webpage
alert() produces a side effect of the user seeing an alert in the browser. Math.max() just produces a value
Control flow is how statements are executed in a program, such as if statements. The order is from top to bottom.
Conditional execution is where there are multiple branches, and the program takes the proper branch based on the situation.
1)A fragment of code that produces a value is called an expression.
2)a declaration of a value. To catch and hold values, JavaScript provides a thing called a
binding or variable. ten = 10, x = 5 redeclaration is possible… ten = 11
3) the collection of all given bindings and their values represent the environment
4) function is a type of value, executing a function means applying a function
function(“argument”); one can expect that sth. will happen when calling a function (eg pop-up?)
5) alert(Math.min(5,9));
//pop up–>5
6) Showing a dialog box or writing text to the screen is a side effect.
7)
let num = Number(prompt(“Pick a number”)); //side effect: prompt --> popup
if (num < 10) {
console.log(“Small”);
} else if (num < 100) {
console.log(“Medium”);
} else {
console.log(“Large”);
}
alert(Math.min(5,9)); // both: side-effect due to alert & produced value 5
//–>5
If a program contains multiple statements, the statements will be processed straight from top to bottom (process flow):
let a = 6, b = 5;
let a = 5;
console.log(a+b);
//–> 10 (not 11)
If a program has decision branches like if/else the process flow is branched this is called conditional execution.
10) if
A fragment of code that produces a value . Every value that is written literally (such as 99 or “CryptoMillionaire”) is an expression.
A placeholder to catch and hold values. Names of bindings can be any meaningful words to describe the value, with the exception of keywords that are reserved like ‘let’, ‘var’, ‘const’ and other words that would create a syntax error should one try to use them as the name of the binding. Bindings do not contain values, they catch/grasp/retrieve them.
The collection of bindings and their values that exist at a given time is called the environment
A function is a piece of program wrapped in a value. Such values can be applied in order to run the wrapped program.
prompt(“Enter passcode”);
Showing a dialog box or writing text to the screen is a side effect
the function Math.max takes any amount of number arguments and gives back the greatest.
console.log(Math.max(2, 4));
// → 4
8. The order in which statements, instructions, or functions of a program are executed.
9. controls whether or not the core will execute an instruction.
10. It’s created using the ‘If’ keyword.
Just a couple of additional observations regarding conditional execution:
That’s right … and I would also add that the decision about which “branch” to take is based on whether a condition (a Boolean expression) evaluates to true or false . This is key to how conditional execution operates within a program.
Just to be clear… you are right that if (and else) are the keywords used; however they are not “Boolean operators” — in fact there is no such thing as a “Boolean operator” in JavaScript. The if and else keywords declare that a conditional statement follows. An if statement has a conditional expression enclosed in parentheses directly after the if keyword and before the code block wrapped in curly brackets. This conditional expression is also known as a Boolean expression because it evaluates to one of the two Boolean values true or false. Boolean expressions commonly are Comparison operators and logical operators are commonly used in conditional/Boolean expressions.
… again, to clarify… you can have:
individual “chains” with more than 2 branches — in which case the else if (or multiple else if') keywords are often used after the intial if and final else statements;
if...else pairs (or longer if...else if ....else chains) nested within outer ones.
In this piece of code, Math.min(2, 4) is a function that produces a value (2), and the console.log() that it’s wrapped in is a function that produces a side effect, the side effect being printing the value produced by the inner function (2) + 100 (102) to the console.
We need to be more specific here e.g.
Conditional execution is where the program’s control flow takes only one of two alternative paths. The decision of which path to take is based on whether a condition (a Boolean expression) evaluates to true or false (i.e. whether the the condition is met or not). Where a series of consecutive conditions are used, only one of several alternative paths will end up being executed.
What is an expression?
A fragment of code that produces a value
What is a binding?
Also known as a Variable, they are used To catch and hold values in memory.
What is an environment?
The collection of bindings and their values that exist at a given time
What is a function?
a piece of program wrapped in a value
Give an example of a function.
function countApples = (3+1);
What is a side effect?
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.
prompt(“Enter passcode”);
function countApples = (3+1);
What is control flow?
When there is more than one statement it uses control flow to go top to bottom
What is conditional execution?
Taking the proper branch depending on the situation or inputs given
What kind of keyword do you need to use to invoke conditional execution?
binding gives an element a value so it can be stored.
3.a collection of bindings and their given values that exist at a given time.
4.a piece of program wrapped in a value.
5.prompt
changeing statement that could change the internal state of the machine and the statements that come after it.
prompt or log are examples of functions that give a side effect.
control flow of a program is when the program you have more than one statement and it is the path taken to execute the statements in the programme, read like a story.
It is a logical test that determines which path to follow , if or else , true or false
Binding, Functions and Control Flow-Reading Assignment
What is an expression?
To use an analogy in the Javascript language an expression is akin to a sentence fragment. It's any piece of code that produces a value. ANY PIECE
What is binding?
A binding is when you attach a specific value to a variable. Ex. Let 3 = 1, 7 = 5; Console.log(7 / 3); // ->5
What is an environment?
An environment is the collection of bindings that exist at any given time within the machine.
What is a function?
A function is a section of code wrapped within an expression.
Give an example of a function.
a classic and widely used function is to invoke console.log( insert expression/variable?here)
What is a side effect?
when and only when a "statement" effects the "world" it is classified as a "side effect"
Give an example of a function that produces a side effect and another that produces a value.
console.log (8 * 8); // -> 64; is an example of a function producing a value. prompt (hire the guy who wrote this); changes the world and as such produces a side effect (of stacking massive sats fyi😉)
what is "control flow"?
to put it simply control flow is the way the functions are executed.
What is conditional execution?
it is a way to add logic to a program. Now will only execute a function when the proper input is detected.This is characterized generally by an "if" though "else" and "switch" are also effective. This allows your program to change or "loop"
what kind of keyword do you need to invoke conditional execution?
adding "if" "switch" or "else" will call a conditional execution
…it can be, but an expression can also just be a single value. An expression is any piece of code that evaluates to (produces) a value.
…not really… binding and variable are two alternative terms for the same thing: any value or expression which has been assigned to a name (effectively labelled) in order for it to be stored in the computer’s memory, and then accessed and reused by the program whenever required.
This is a good mathematical representation of a function. An example specific to JavaScript could be either of the following:
alert("This is an alert!");
function f(x) {
return x + 3;
}
Yes… but all functions produce results (outputs). A side effect is a specific type of output — an action which occurs externally (outside of the program).
Yes…the alert() function produces a side effect, and the side effect is the alert pop-up that appears in the browser when this function is executed.
…while this is true, the question asks for an example of a function that produces a value. An example would be:
function f(x) {
return x + 3;
}
…more specifically, it refers to the order in which individual pieces of code (i.e. statements, functions, loops, variables etc.) are executed or evaluated. Control flow enables the computer to correctly decide which path to take through a program, from starting at the top, to finishing at the bottom.
I hope this makes certain aspects clearer, and gives you a better understanding of this section.
That’s right … and I would also add that the decision about which “branch” to take is based on whether a condition (a Boolean expression) evaluates to true or false . This is key to how conditional execution operates within a program.
Excellent answers, with some nice detail, @Mujtahid_Haque!
I can see you’ve put a lot of thought and effort into this assignment.
That’s right … and I would also add that the decision about which “branch” to take is based on whether conditions (Boolean expressions) evaluate to true or false . This is key to how conditional execution operates within a program.
Yes … and I would also add that the decision about which “branch” to take is based on whether conditions (Boolean expressions) evaluate to true or false . This is key to how conditional execution operates within a program.
Yes… and in this piece of code, Math.max(2, 4) is a function that produces a value (4), and the console.log() that it’s wrapped in is a function that produces a side effect, the side effect being printing the value produced by the inner function (4) to the console.
That’s only really half the story… conditional execution is more about controlling which of two or more alternative branches of code will be executed next. The decision about which “branch” to take is based on whether conditions (Boolean expressions) evaluate to true or false (i.e whether they are met or not).
This is a strange cross between a binding and a function
A function in JavaScript can be declared and then called (executed) as follows:
function countApples(firstTree, secondTree) {
return firstTree + secondTree;
}
let totalApples = countApples(30, 10);
console.log(totalApples); // => 40
The first 3 lines of code (the actual function) would also be the example of a function that produces a value for your answer to Q7.
Yes … and I would add that the decision about which “branch” to take is based on whether a condition (a Boolean expression) evaluates to true or false . This is key to how conditional execution operates within a program.
An expression can be an integer, string, any fragment of code which produces a value. an expression between parenthesis or a binary operator between 2 expressions.
What is a binding?
Bindings are synonymous with variables. They are simply a means to assign and store values which can be easily recalled later on.
What is an environment?
An environment is a collection of bindings and their current values. The environment is also a collection of settings related to the machine and even the browser has its own environment and settings such as window state and size for example.
What is a function?
A function is a small program which runs inside a larger program and can return values or make changes as the main program runs. They can perform tasks such as simply adding two numbers together and returning the value or make changes to the running state of the environment. I like to think of them as reusable chunks of code.
Give an example of a function.
The example function i will give will add 2 numbers together and return the result
function addMe(val1, val2) {
return val1 + val2
}
What is a side effect?
A side effect is something that happens other than producing a value such as moving an object on screen or opening an alert box.
Give an example of a function that produces a side effect and another function that produces a value.
Function to produce value
Math.floor{Math.random() * 100) + 1
Function to produce a sideeffect.
alert(Math.floor(Math.random() * 100) +1)
What is control flow?
Control flow relates to the execution of statements in a program. The flow travels from top to bottom so the first statement on the top of the page executes first and last statement at bottom of page executes last.
What is conditional execution?
Conditional execution is a way of isolating snippets of code within the control flow and only executing the contained code when a particular condition is met.
What kind of keyword do you need to use to invoke conditional execution?
The keywords if, else if and else are used to control conditional branching for example:
if (condition) {
do this;
} else if {
do this;
} else {
do this;
}