- code that produces a value is an expression
- bindings point from a variable to its current value
- the sum of all bindings is the environment.
- a function is code that is wrapped in a value.
- console.log()
- A side effect is any expression or function that displays or otherwise changes the string or value on the webpage. thanks to @Bladeskiosity
- alert(âhello side effectâ)
- controll flow is order that the programm gets executet
- conditional execution is used to direct the controll with conditional statements
- for example if , elseif , else
What is an expression?
- Code built from variables, operators which produces a value.
What is a binding? - variable assignment that points to values
What is an environment?
-A programâs collection of variables/bindings and the given values.
What is a function?
-Expression wrapped in a value which can be called (run) to perform.
Give an example of a function.
-Math.max(11,22);
What is a side effect? - Expression or function which would change a value of a value or property on a webpage.
Give an example of a function that produces a side effect and another function that produces a value. - prompt("⌠and weâre live ______");
What is control flow?
-Determines the execution order of code based on values or outcomes.
What is conditional execution?
-Values or actions that are driven by prompts from users.
What kind of keyword do you need to use to invoke conditional execution?
-if, else
- An expression is a fragment of a code that produces a value
- A binding is a resource that enables you to catch and hold values.
- An environment is the colection of bindings you have at a given time
- A function is a piece of program wrapped in a value (that sort of values arte called arguments)
- An example of a function can be:
alert(âThis course is awesome!!â); - A side effect is the change that a statement result can generate on the next statement (inside of the same block or program)
- An example of a function that produces a side effect:
alert(âside effectâ);
An example of a function that produces a value:
console.log(2+3); - Control Flow is the way statements are executed by the program. They are always executed from left to right, from top to bottom.
- Conditional execution is a resource utilized when you want some code to be executed if a certain condition holds. It allows you to take diferent paths given diferent situations
- To invoke conditional execution I need to use the keyword if. if I have more than 2 diferent paths, I need to use the keyword if and the keyword else
Is this an okay place to ask questions? If not, where do I go (to remain in the forum, per my understanding of Ivanâs request.) Rather than await an answer, Iâll pose my question. Answers from the community are, I suppose, optional; but do please direct me to the right place to ask things about reading and assignments if necessary.
The example says:
let theNumber = Number(prompt(âPick a numberâ));
console.log("Your number is the square root of " +
theNumber * theNumber);
Not understanding the Number() function, I tried removing it:
let theNumber = prompt(âPick a numberâ);
console.log("Your number is the square root of " +
theNumber * theNumber);
That worked fine, too. The text subsequently says the Number() is used to covert the value (string?) to a numeric, but JS seems to be so untyped (or just plain smart) that it does it automatically.
Could it be that the JS Iâm using was released after EloquentJava was published, and the newer release guesses that strings of characters known to be digits with subsequent arithmetic operations should be converted when possible? If thatâs NOT the reason, then what is?
BTW, if this IS the place for questions, why donât I see others?
Trying something different, all answers are quoted from âeloquent Javascriptâ; as this for me has the most concise answers written in the shortest use of language ;-).
- An expression is âa fragment of code that produces a valueâ.
- Binding âcreates a new function that will call the original function but with some of the arguments already fixedâ
3.The environment is a âcollection of variables and their values that exist at a given timeâ.
4.A function is " a piece of program wrapped in a value" and the value can âbe âappliedâ in order to run the wrapped programâ
5.Ex: Alert Function ; alert(âGood morning!â); wheras the funtion being the program telling what to do when applied, and the value being the string âGood morning!â - Side effect is something that can âchange the internal state of the machine in a way that will affect the statements that come after itâ.
- So âshowing a dialog box or printing text to the screen is a side effectâ , in the example of Math.max, "it takes any number of number values and gives back the greatest: console.log(Math.max(2,4)); Result=. (Returns â4â)
- control flow is a prdictable execution of statements ie: top to bottom
- Conditional execution is âwhere we choose between two different routes based on a Boolean valueâ.
- if, if/else
Hey afs,
I think you are in the right place for questions ect. Hey I just noticed perhaps did you accidentally put âletâ instead of âvarâ the number as in var theNumber = Number(prompt(âPick a numberâ));
?
Thats the best I got right now, Iâm still learning too,
Good luck.
YellowCake
So AFS,
If Iâm understanding you correctly, you were having trouble with figuring whatâs what with âtheNumberâ mumbo jumbo, I am going to attempt to explain in a different way.
So, the first part of the code is setting a âvarâ called âtheNumberâ, it could just as easily be called âchickenâ if it makes it less confusing to first understand: as in, var chicken = 3
Now whenever you type âchickenâ, you will get a response of â3â, because we created a var named chicken with an assigned value of 3.
So now we are simply creating a âvarâ called âtheNumberâ and saying it is equal to the next few things⌠so the âvarâ is = prompt ------which is a function of itâs own (like a command)------- (âPick a Numberâ) , this âPick a Numberâ) is the âStringâ or sentance we want to be prompted by the âpromptâ functionâŚ
Hope this gets you on the right track, and by me tring to answer your questions, although Iâm not an expert, it helps me learn as well. At first I thought, I wasnât going to participate in tring to help others because I am pretty new myself, but now I see the value as it helps me as well.
I hope I at least helped you a bit.
YellowCake
Iâm using the 3rd edition of EloquentâŚ, and the book uses let. Earlier reading made me think that if var isnât technically deprecated, itâs still mostly o/o fashion (they said theyâd explain later.)
Since I got your note, I tried it with var, both ways, and thatâs cool too. I read on a bit, and I see they make a routine for what happens if you put in a non-numeric, and thatâs fine. Iâm happy to read on and see what they have to say.
But honestly, teaching materials that arenât straightforward, or are ambiguous drive me ka-razy.
The introduction had this tidbit under typographic conventions:
function factorial(n) {
if (n == 0) {
return 1;
} else {
return factorial(n - 1) * n;
}
}
I didnât drive myself to hard on this, since it was only about typographical conventions but â you know â I tried to understand the script anyway, but it was very hard. I tried to write it longhand, starting with n at 5 or something, but I got stuck owing to the recursion. Maybe if I start at 1 (the exit point) and work my way up to 5, Iâll understand it. My point is only that if youâre teaching a person to drive, you donât give the general theory of relativity as an example of why GPS works, even though there will be GPS in the car. There are other ways to help a person get familiar with the environment.
Ah, I see youâve sent a second note. Alas, it doesnât address the question. That question is:
Why Number(prompt(âPick a numberâ));
Instead of prompt(âPick a numberâ);
Either will yield correct results, whether used with let OR var. If, as they point out later, a non-numeric input has to be accounted for, then we can add the number() function later as part of an input error trap. But this is a section on control flow and, as such, I see no need to muddy the materials with extraneous things. Anyhow, weâll soldier on. Itâs early, and Iâm still calibrating the degree to which I put faith in my learning materials.
I get you, it sounds perhaps, at this point you know more than I do, hope you can help me when Iâm stuckâŚCheers.
If thatâs the case, you might be in trouble.
But Iâm not worried; weâll figure it out â much sooner than we could commit to memory the 48 preludes and fugues (which many who lack genius have done.)
- An expression is a piece of code that creates a value
- A binding sets a value to another value
- The collection of bindings and their respective values at any given time is called an environment.
- A function is a program inside of a value
- prompt(âEnter Passcodeâ);
- When something is executed and changes the way the machine affects the statements after it.
- Non-Side Effect: 1; Side Effect: let ten = 10; ten + 10;
- Control flow is the way that javascript reads code, which is top to bottom.
- Conditional execution is when the program executes certain lines of code depending on the given condition.
- âifâ
expression.
a fragment of code tha produces value is called an expression.
1)Expression.
every value written literally such as 22 is an expression.
2)Bindings.
bindings is a java script tool which it uses to catch and hold values.
3)The environment.
a collection of bindings and their values that exist at a given time
is called an evironment.
4)Functions.
a function is a program wrapped in values, this values can be applied to
to run the wrapped program.
5)Example of functions.
an example is the console.log function, which prints out its argument to a
text output device. It is an expression that retrieves the log property from the
value held by the console binding.
6)Side effect.
showing a dialog box or writing text to the screen is called a side effect.
7)example of function that produces a value is
console.log(math.max(7,9)+305);.
8)Control flow.
control flow is the order in which individual statememnts, instructions, or
function calls of an emperative program are executed or evaluated.
9)Conditional execution.
it is the statemenent that holds the flow of executions depending on some condition.
example we want some code to be executed if and only if some certain conditions hold.
10)the keyword used for invoking conditional executions is the âifâ word.
1- A fragment of code that produces a value
2 - Binding is tying up a value to a named variable so that it can be stored in memory and not disappear after use
3 - A collection of bindings and their respective values that exist at a given point in time
4 - A binding that contains a set of instructions
5 - console.log(value);
6 - It is what happens when a function is invoked. Examples could be a value being returned or a dialog box pop-up requesting user input
7 -
Side effect: prompt();
Value: Math.max(a,b);
8 - Control flow is used to adjust the order in which a program executes statements
9 - Executing different statements according to pre-established conditions
10 - if
What is an expression?
An expression is a segment of code that produces a value.
What is a binding?
A binding is a variable that points to a value. This value could be produced by an expression.
What is an environment?
An environment is the entire collection of bindings and variables in use.
What is a function?
A function is a program segment that runs when invoked. Using the â( and )â after a value that is a function invokes the function.
Give an example of a function.
result = SafeMath.add(x,y);
In the above example, the add method/function is invoked from the SafeMath library. It takes two parameters, adds them together, and returns a result that is then pointed to by the result variable.
What is a side effect?
A side effect is any state change occurrence that is not a returned value from the result of an invoked function.
Give an example of a function that produces a side effect and another function that produces a value.
The console.log() function is an example of a function that has a side effect, outputting to the screen.
An example of a function that returns a value could be the Math.min() function. It returns the smallest single value out of the parameters that have been passed.
What is control flow?
Control flow is the order in which a program executes. A basic program starts with a linear flow. Control flow could be altered through the use of an if statement. This if statement would create a fork in the flow of a program.
What is conditional execution?
An example of conditional execution would be similar to the if statement example above. If statements can take an expression as a parameter and if it results in a true boolean value, the following code segment will run. If not, the code segment following the else keyword will run.
What kind of keyword do you need to use to invoke conditional execution?
Keywords used to invoke conditional statements include if and else.
-
An expression is a fragment of code that produces a value
-
A binding let the program keep an internal state and remember things
-
An environment is the collection of bindings and their values that exist at a given time
-
A function is a piece of program wrapped in a value
-
prompt function , console.log function
-
a side effect is a âstate being changedâ in the program (showing a dialog box for example)
7)Example of a function that produces value :
let a = 1;
let b = 2
console.log(Math.min(a,b));
â> 1
Example of a function that gives a side effect
prompt(âwrite your nameâ); -
control flow is the order the statements are executed (from top to bottom)
-
Conditional execution is where the program takes the proper branch based on the situation at hand .
-
if, else if, else
What is an expression?
⢠An expression is piece of code that produces a value
What is a binding?
⢠A binding links a variable to a value.
What is an environment?
⢠An environment is the collection of bindings and their values.
What is a function?
⢠A Function is a chunk of code wrapped in a value
Give an example of a function.
⢠console.log(âThis is technically a functionâ);
What is a side effect?
⢠A side effect happens when an expression changes something about the machine (usually something in memory), which will have an impact on code that runs later.
Give an example of a function that produces a side effect and another function that produces a value.
⢠Side Effect:
â console.log(âThis function has the side effect of writing to the browser console.â);
⢠Value
â Math.max(2, 4);
§ //This function returns the integer value of 4
What is control flow?
⢠Control flow is the order in which lines of code are executed.
What is conditional execution?
⢠Conditional execution decides which lines of code will run next based on conditional logic.
What kind of keyword do you need to use to invoke conditional execution?
if, else, while, do, and for are keywords that can be used to invoke conditional execution.
1.An expression is a fragment of code that produces a value.
2.A binding or variable is the way you assign,catch and hold values in Javascript.Its function to keep the internal program state.A binding is valid as long as its not changed by an expression or process.
3.An environment is a collection of bindings or variables and their values at any given time.
4.A function is a piece of program wrapped in a value.
5.An example of a function is fi: call the âpromptâ function which results in an action from the Javascript engine in the browser:this opens up a dialog box.
6.When a function produces an interaction with the user beyond the value it renders internally is called a side-effect.
7.Showing a dialog box or writing text to screen are examples of a side-effects of functions,whereas the real function only renders a value.
example value: value= x
8.The control flow is the order in which the program executes the functions in the script,usually from top to bottom as a story.
9.A conditional execution is only performed when certain circumstances in functions are met.
- with the help of the keywords âifâ and âelseâ.
What is an expression? A fragment of code that produces a value
What is a binding? A binding, or variable, is used to store values
What is an environment? A collection of bindings and their values that exist at a given time.
What is a function? A function is a part of a program that has been assigned to a value.
Give an example of a function. alert(âHello Worldâ);
What is a side effect? Showing a dialog box or writing to the screen.
Give an example of a function that produces a side effect and another function that produces a value.
side effect: alert(âHello Worldâ);
value: Math.max(4,2);
What is control flow? The order in which the program executes
What is conditional execution? The flow of the program may change paths based on conditions set in the program.
What kind of keyword do you need to use to invoke conditional execution? if
-
What is an expression?
A piece of code producing a value -
What is a binding?
The assignment of a value to a variable -
What is an environment?
The current state of the program / machine, as defined by its collection of variables and their values -
What is a function?
A piece of program that produces / assigns values -
Give an example of a function.
x = 1 + 2; -
What is a side effect?
The effect that code has on the state of the machine if perceivable by the user -
Give an example of a function that produces a side effect and another function that produces a value.
Side effect: console.log(âhello world!â);
Value: y = 2+5; -
What is control flow?
The order in which the program is executed. Typically this is top-down, left-right, unless interrupted or conditional -
What is conditional execution?
When the execution path of code is influenced by decisions of the if-then type: IF x DO a, ELSE DO b -
What kind of keyword do you need to use to invoke conditional execution?
If