-
An expression is a fragment of code that produces a value.
-
A binding is there to catch and hold values. Javascript provides a binding by using keywords. The keyword indicates that the sentence is going to define a binding.
-
An environment is the collection of bindings and their values that exist in that given moment.
-
A function is an expression wrapped in a value. A lot of the values provided in the default environment have the type function.
-
Here are a couple of examples of a function one is in a browser environment, the binding âpromptâ holds a function that shows a little dialog box asking for input and another is the âalertâ function which displays a pop up message.
-
A side effect is any function which displays or changes the webpage visibly by showing a dialog box or writing text to the screen.
-
One example of a function that produces a side effect and another function which produces a value is alert(âalert is a functionâ) and (Maths.max) function returns a value.
-
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.
-
Conditional execution is when the program takes the proper branch based on the situation at hand. There could be a straight road and then based on the situation the program can take a branching road this is called conditional execution.
-
The keyword you need to use to invoke conditional execution is if. You can create two separate, alternative paths using together if and else.
Any unit of code that can be evaluated to a value is an expression.
A binding or variable trough special keywords (such as var, let and const) grasp and hold value .
It is followed by the name of the binding and, if we want to give it a value, by the = operator and an expression.
After a binding has been defined, its name can be used as an another expression. The value of such an expression is the value the binding currently holds.
Is a collection of bindings and their values that exist at a defined time.
Is a piece of code designed to perform a particular task and is executed when âsomethingâ invokes it (calls it).
prompt(âEnter Nicknameâ);
A side effect is basically when we change the state of the program through an indirect means.
- I call this function
- I get a direct result back.
- I get some direct effect back, but I also change something else about the state of my program.
function that produces a side effect:
let theNumber = Number(prompt(âPick a number , i will multiply for 50 timesâ));
console.log("Your number multiplied for 50 is " +
theNumber * 50);
function that produces a value:
console.log(Math.min(22, 44) * 10);
The control flow is the order in which the program executes statements in a script.
There is a conditional execution when we âtellâ the program to perform different actions based on different conditions. It is invoked with the keywords mentioned below.
else if , else , if , switch
-
What is an expression? a fragment of code that produces a value, can be as short as 22, or âpsychoanalysisâ, Expressions can contain other expressions. Expressions donât change anything, they merely produce values which then can be used by the program. Anything that returns a value can be called an expression.
-
What is a binding? (or variables) enable a program to memorise values by tying the value to the binding. Bindings consist of a command (i.e. âletâ) in combination with the name of the binding (keyword)
-
What is an environment? a collection of bindings and their values
-
What is a function? Functions are values representing a piece of program which come predefined with the default environment of the programming language. They can be called/invoked in order to execute their program.
-
Give an example of a function. console.log
-
What is a side effect? Functions that influence the following statements are called side effects. These are functions with no immediate effect but change the internal state of the machine.
-
Give an example of a function that produces a side effect and another function that produces a value.
Side-effect: var = 55, a = âsimpleâ
Function: console.log(Math.max(2, 9)); let animal = âElephantâ -
What is control flow? Specifies in what order consecutive statements are to be executed. This might be linear, i.e. one after the other,
-
What is conditional execution? or the execution order can be adjusted to expand on capabilities, such as the âif / elseâ statement which intersect predefined conditions that have to be met before deciding which will be the next statement to be executed
-
What kind of keyword do you need to use to invoke conditional execution? if / else
What is an expression? A fragment of code that produces a value.
What is a binding? Bindings make programs keep an internal state, remember thingsâŚ.catch and hold values.
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. These values can be applied in order to run the wrapped program.
Give an example of a function. Dialog boxes in a web browswer asking for user input.
What is a side effect? Change the internal state of the machine in a way 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. A side effect would be âHello Worldâ simply writing text to the screen. Function to value would be console.log(Math.max(2,4));
// > 4
In the above example Math.max takes any amount of number arguments and gives back the greatest.
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. I cut and pasted the example in our book into the console and used the number 5. The return read, âyour number is the square root of 25â. The function Number converts a value to a number, which is needed because the result of the prompt is a string value, and we want a number.
let theNumber = Number(prompt(âPick a numberâ));
console.log("Your number is the square root of " +
theNumber * theNumber);
What is conditional execution? Not all programs are straight roads. You may want to create a branching road, where the program takes the proper branch based on the situation at hand. Conditional execution is created with the if keyword in JavaScript. Example, want to show the square of the input only if the input is a actually a number:
let theNumber = Number(prompt(âPick a numberâ));
if (!Number.isNaN(theNumber)) {
console.log("Your number is the square root of " +
theNumber * theNumber);
}
What kind of keyword do you need to use to invoke conditional execution? if
- According to the author, âan expression is a fragment of code that produces [or represents?] a value.â
- I donât think that the definition of âbinding,â given in the text, is fully coherent. Initially, the author defines a binding to be a variable, but then he goes on to refer to constants and functions as bindings as well. So it seems to me that a binding is really just a name of either a variable, a constant or a function. The problem, though, with that latter interpretation is that the author seems to distinguish between bindings and binding names. This makes some sense insofar as a function, for example, is more than just a name, but it still leaves me wondering exactly what the author means by a âbinding.â. The word itself seems to suggest the notion of an association of a name with an entity (or value) that is being named, but a proper definition of such an association is simply not provided. (Sorry for being so exacting, but I am a professional math guy, and reading and writing precise definitions is basically what I do for a living.)
- According to the author, the environment at a given moment in time is the totality of all the bindings.and their values at that moment.
- A function is a rule of assignment that uniquely associates elements in a given domain with elements in a given range.
- domain: all positive integers; range: all integers greater than one; riule of assignment: f(x)=x+1.
- So far as I can tell, a side effect is a real-world observable changeâin the CPU, in the memory, or on the screenâthat is brought about by a statement and possibly affects other, subsequent statements (but again, the notion of a statement is not rigorously defined).
- f(a,b)=a+b produces the value a+b from the input (a,b) and prompt(string) produces a pop-up window with âstringâ displayed on it above an input field. I wonder, though, whether the distinction is really well defined because the value a+b, it seems to me, cannot be produced without some actual real-world changes in the CPU and/or the memory.
- Again, I donât think that the author defines the notion of a control flow very clearly, but so far as I can tell, a control flow is a schematic representation of the logical structure of a program.
- A conditional execution is a command execution that is carried out only if a certain prior condition is satisfied.
- âifâ or (âifâ and âelseâ).
- A fragment of code that produces a value is called an expression.
- It is a function that stores old values.
- It is a collection of bindings and their values that exist at a given time.
- A function is a piece of program wrapped in a value.
- prompt(âenter phone numberâ);
- Showing a dialog box or writing text to the screen.
- Side effect: prompt(âenter phone numberâ);
Value: math.max(2, 4); - It is the order in which the statements are executed.
- It is a function that is executed only when a certain condition is met.
- if
-
What is an expression?
code that produces a value -
What is a binding?
a variable that stores values -
What is an environment?
a collection of bindings and their values -
What is a function?
a piece of program wrapped in a value -
Give an example of a function.
prompt(); -
What is a side effect?
a modification of some sort of state -
Give an example of a function that produces a side effect and another function that produces a value.
var a = âHelloâ
â> side effect: a=âhiâ
â> function: Number.isNaN(a); -
What is control flow?
Execution of statements from top to bottom -
What is conditional execution?
Executes a statement only if a certain condition holds -
What kind of keyword do you need to use to invoke conditional execution?
if(){}, else if (){} or else(){}
- a fragment of code that produces a value
- bindings are variables
- collection of binding and their values
- A function is a piece of program wrapped in a value. Such values can be applied in order to run the wrapped program
- alert(âenter birthdayâ)
- Showing a dialog box or writing text to the screen
- console.log(Math.max(2, 4))
- means that the program executes one statement after the other beginning from the top
- If, statement: let number=(âpick a numberâ); if number <=10 show number; booleans is usually a true or false statement.
- if
Thanks for the feedback. Iâve been reading up and studying and think Iâm grasping the subject now. When I did this post, I was think I was fairly comfortable with the idea of of functions with return values so I gave as simple an example as I could think offâŚThe side effect concept was what I was trying to wrap my head aroundâŚthe reason this seemed harder to grasp is because while everything Iâm seeing says to try to have pure functions and side effects are bad, to me they seem like a good ideaâŚdefine variables outside of function and call on them in functions when neededâŚ
Anyway, just to clarifyâŚI think what you are saying is that the return value I gave is indeed an example of a return value, that has no side effects, but is a pointless function. Is that right?
I do appreciate the time and feedback very much by the way, thank you.
- An expression is a fragment of code that produces a value ;
- A binding is a sentence that define a relation between a variable tag and its value :
Ex :
let drink = "beer!"; //binding assignment of a value `beer!` to newly generated **drink** tentacle !//
console.log (drink);
beer!
-
An Environment is the collection of bindings and their values existing at a certain time in a program;
-
A function is a program wrapped in a value;
-
To call a Function like
Prompt
will trigger a prompt window pop-up in the web browser :
prompt("Fill this field with value");
-
In the previous code, prompt invoking a windows with an entry field to collect a value is a side effect;
-
prompt("Fill this field with value");
will produce a windowed pop-up as a side effect;
console.log(Math.min(2, 4) + 100);
will return the value102
; -
Control flow is a programâs statements execution path drawn according to test functions in the code.
for example : -
A conditional execution is a function that needs a boolean result to chose between two path of execution. One for
True
, one forFalse
. -
You need those keywords :
if
,else
,for
,while
,do
, to trigger a conditional execution function.
-
An expression is a fragment of code that makes up statements, and a program is basically a list of statements that produces side effects. An expression could be a piece of code that produces a value. The value may be a string, number or logical value. A binary operator applied to two expressions is also an expression, as i a unary operator applied to one. The ternary operator is also an expression. And every value that is written literally is an expression. You can think of this similar to how human languages work. Expressions can contain expressions just like human sentences are nested, a subsentence can contain its own subsentences and so on. âThis allows us to build expressions that describe arbitrarily complex computations.â
-
A binding is what lets JavaScript remember stuff by âbindingâ a value to a name, variable or constant and lets us programmers define these bindings and assign our own values as we see fit. Exept of course if we would try to define some of the reserved words or keywords that has special meaning in JavaScript.
-
An environment is the collection of bindings and their values at any given time. A program always has an environment, even a âemptyâ program that just barely has code, still isnât completely empty as it has an environment of bindings that are part of the JavaScript language standard (mentioned above).
-
A function is a block of code or âsubprogramâ, designed to perform a particular task. Just like the program itself, a function consists of a sequence of statements called the function body. Values can be passed to a function, and the function will return a value. In JavaScrpit we can define our own functions using the function keyword.
-
function showMessage() {
alert( âGet rich 4 sure!â );
}
showMessage; -
A side effect is something that âaffects the worldâ, has an âeffectâ or is somehow observable. For example, displaying something on the screen or changing the internal state of the machine in a way that affects the statements that come after it. The function above has the side effect of alerting the user of a webpage âGet rich 4 sureâ in a popup-box in the browser.
-
alert(âThis is a side effectâ);
console.log(1+1); -
Control flow is simply the order in which to execute the functions. It starts from the first line and proceeds to the last, unless something alters the control flow. For example conditional execution and loops.
-
Conditional execution to execute a function whether or not something is true. This creates branching paths in a program and can alter the control flow.
-
Conditional execution is created with the if keyword in JavaScript. This makes it so the following code only executes IF a certain condition holds. To create an alternate branch, the else keyword is used. If you want to have more than two paths to choose from, you can chain multiple conditions by using if / else if / else.
-
An expression is a â fragmentâ or âcomponentâ of Javascript code that resolves to a value. Or, put another way, âany unit of code that can be evaluated to a value is an expressionâ
-
A binding [or variable] is a way of assigning or defining values in the current memory as expressions or âcomponentsâ to be used in a statement.
I found this definition useful; âBinding something in JavaScript means recording that identifier in a specific Environment Record. Each Environment Record is related to a specific Execution Context - and that binds the identifier (variable or function name) to the this keyword for that execution context.â -
The environment is the current active running âcollection of bindingsâ or definition state.
-
A function is something that can resolve expression in statement into value . Or, put more exactly, âA function is a JavaScript procedure - a set of statements that performs a task or calculates a value. To use a function, you must define it somewhere in the scope from which you wish to call it.â
-
A function example -
console.log(2*2) -
A side effect is a change brought about by a statement that âchanges the worldâ in the sense that it has an active effect - either visibly, eg by generating a number and printing it, or non-visibly - by altering the setting or internal operation of the script so that itâs state has changed.
-
a = 2 would produce a side effect in the sense that the letter a would now have a binding to the number 2, and therefore, a + a would now produce a value of 4.
-
Control flow is a way of introducing - and controlling - multiple options if and when certain conditions are met.
-
Conditional execution is a process by which certain events may or may not happen [be executed], dependent on meeting certain conditions.
-
The keyword let is used to invoke conditional execution.
-
What is an expression?
The code that produces a value. -
What is a binding?
A binding, also called a variable, is to catch and hold the values. -
What is an environment?
The collection of bindings and their values that exists at a given time. -
What is a function?
A piece of program wrapped in a value. -
Give an example of a function.
console.log function, which will output values to the console. -
What is a side effect?
The expression and the statement may change the internal state of the machine in a way that will affect the statements that come after it, the changes are called side effect. -
Give an example of a function that produces a side effect and another function that produces a value.
a side effect: prompt(âEnter your ageâ);
a value: Math.max(3,7); -
What is control flow?
Multiple statements in a program are executed in an order. -
What is conditional execution?
A program will take next action based on some conditions or criteria. -
What kind of keyword do you need to use to invoke conditional execution?
IF and ELSE keyword;
yes, that is a more close âreturn valueâ example. a Side effect is more likely to not return a value, it does something with a parameter, but it does not change it or create something else from the given parameter.
If you have any more questions, please let us know so we can help you!
Carlos Z.
Hi @jwafe,
Nice answers
Just one commentâŚ
Not all functions produce side effects. Some just return values. One type of side effect is when a function causes a meaningful action to occur externally (outside of the program) e.g. logging an output to the console, or generating a pop-up dialogue box.
-
every input that resolves to a value is an expression (f.ex: 1, a or (1+2))
-
binding is like attaching some information to a named object. let name = âZlatan Zlatanimovicâ. So the programe now remembers that the name is Zlatan âŚ
-
It is a collection of bindings and their values at a given time
-
A function is a piece of program wrapped in a value
-
prompt(âHello Ivan and Filipâ)
-
the effect in example 5. has the side effect of a window popping up on the screen.
-
prompt(âHello Ivan and Filipâ) = side effet and console.log(Math.max. (2,4,7)) = value (7)
-
Control flow means that the program runs from top to bottom. So if a program consists of more than one statement they will be executed in top to bottom order.
-
it is a execution that is only being fulfilled if a certain statement is true.
-
if, else
-
An expression is every kind of value (numbers or words) written in a line of code and which finish with a semicolon.
-
A binding or also called a variable catchâs and holds value and connect it to another value. Bindings are not tied to values forever, the can be easy disconnected and tied to another value.
-
A collection of bindings with their values which exist at the time the program is operating.
-
In Haverbekeâs book a function is a piece of program wrapped in a value which can be applied to ran a program, but in my understanding, it is the value which is wrapped into the function.
-
The draw function, not mentioned in the chapter 2, but one I used recently in a JS animation.
-
A value produced by a function.
-
The prompt function produces as a side effect a dialog box and the function Math.max produce a value.
-
The way a multiple statements in code are executed.
From top to bottom. -
Unlike control flow which execute the statements from to top to bottom, conditional execution is based on a specific situation and created with the key word if.
-
The if and else keyword.
1. What is an expression?
An expression is anytime there is a value that is written literally in JavaScript. Anything that produces a value in JavaScript is an expression.
2. What is a binding?
A binding is a way of attaching a name to a particular value. So if we want the word âtenâ to hold the value of â10â then we could create a binding by writing let ten = 10;
This makes the program remember a value so it can be called upon later more easily.
3. What is an environment?
The environment is simply the collection of all bindings and their values that currently exist within a program. Kind of like how each country will have their own unique expressions, laws, social expectations, each program will have its own unique set of bindings that make up its environment.
4. What is a function?
My understanding of a function is that this a block of code designed to perform a particular task. A function can then be âinvokedâ or called upon to perform that task.
5. Give an example of a function.
console.log
prompt
alert
6. What is a side effect?
A side effect is a result of a function being executed, such as displaying a dialogue box or or writing text to the screen.
7. Give an example of a function that produces a side effect and another function that produces a value.
prompt(âThis is a dialogue boxâ); - Side Effect
console.log(7+8); produces a value
8. What is control flow?
Control flow is the order in which your programâs statements are to be executed, which is done from top to bottom unless conditional execution is used.
9. What is conditional execution?
Conditional execution is when your program will take a different âpathâ depending on the conditions met.
For example, you can tell your program that if someone is over the age of 20 years old, to prompt them with different questions than if they are under 20 years old.
10. What kind of keyword do you need to use to invoke conditional execution?
âifâ and âelseâ
Binding, Functions and Control Flow- Reading Assignment.
What is an expression?
- When writing code on JavaScript, an expression is anything that is a value or anything that is giving value, that you write in fragment code. So the term expression is used to describe the.
Example 5, âjohnâ 2+3, are all a form of expression.
This to is an Expression. You can have an expression with in an expression within a expression.
function countapples = (janeapples,bobsapples) {return janeapples + bobsapple}
What is a binding?
- What JavaScript can do for a developer is provide a way you can hold or save, on your computer code that you gave value. There are special keywords that you can use that can save your value for future reference, one of them is called let.
Example:
let fun = âfootballâ.
next time i write fun in the console it will show under it âfootballâ.
or you can call for it by console.log fun.
But binding values does not mean it will remain as the value permanently. You can also assign a new value by way of expression.
Example:
fun = âtennisâ
so now fun is no longer going to show âfootballâ it will show âtennisâ instead. I just changed the original binding value and giving it a new value.
What is an environment?
- The term the environment is used to describe the collection of bindings or variables and there values. This environment is not empty, binding is always contained in the JavaScript Language, so an example used is a web browser has an environment of preexisting fragment of code that interacts with your mouse and keyboard input. (If any more input for better understanding please share).
What is a function? & Give an example of a function.
4/5 A function is a piece of programme that is wrapped in a value. What this means, when a developer is writing code and you want to run a programme, to make it easy on JavaScript instead of a long code that preforms a specif task you want, its been made short an given a value.
An example of a function is alert. Alert function applies to create a pop up box on a web browser.
alert(âhello worldâ)
What is a side effect?
- When using some Functions that cause to have a interactions with the user on a web page like creating a text box or setting an alert, this is called a side effect. No not all function interact with the web browser in the same way so not all function cause a side effect.
Give an example of a function that produces a side effect and another function that produces a value.
An example of a function that cause side effect is:
promote(âenter passwordâ)
This functions creates a dialog text box and cause a side effect.
A function that doesnât cause a side effect is:
console.log(math.max(2,4));
This will not cause a side effect even though a function was used. Its function purpose math.max is to takes any amount of number
arguments and gives back the greatest. This is a value.
What is control flow?
- What is meant by control flow in programming code is read like a story. The code is read from Top to Bottom. When the programme see more then 1 action to execute it will work its way down.
What is conditional execution? & What kind of keyword do you need to use to invoke conditional execution?
9/10. A conditional execution is used when you are using the âifâ function. Best example i can think of is that, the web site has age restriction and user has to interact with the web page by entering there age. The âifâ function is were this comes in. Your writing in code âifâ there over 21 they can access the website, âifâ they are not then redirect them to this code. where most likely it will show a web page saying you can access this site.
An expression is a fragment of code that produces a value.
A binding is text that allows the script to catch and hold values.
The environment is the collection of bindings and their values that exist at a given time.
A function is a piece of programming wrapped in a value.
alert(âNow Entering Rekt Cityâ)
Side effects are changes in the script that affect all statements that come after it.
prompt("Welcome To Rekt City, Please Enter Your Private Keys")
console.log(11-6)
`> 5`
Control flow is the order in which statements are read, from top to bottom.
Conditional execution is when the control flow is not straight forward, when there are circumstances in which âifâ is used and where certain paths will be followed only âifâ certain values are met.
if, else, else if