Code
A program, often referred to source code or just code, was a set of special instructions to tell the computer what tasks T o perform. Usually, the code is saved. A text file, although with JavaScript can type code directly to a developer console in A browser. The rules for valid format and combinations of instruction are called computer language, sometimes referred as its syntax, Much the same as 中文版 tells you what to spell words and how to create valid sentences using words and punctuation.
Statements
In a computed language, a group of words, numbers and operators that performs a specific task is a statement, such as a = B.
The characters A and B are called Variables, which is like simple boxes to store all of your stuff in. In programs, variable holds the values to be used by program. Think of them as symbolic placeholders for values themselves.
By contrast, the 2 is just a value itself, called a literal value, because it stands alone-without being stored in a vari Able.
The = and * characters is operators, they perform actions with the values and variables such as assignment and mathematic Multiplication.
The statement a = B; Tells the computer to get the current value stored in the variable b, multiply that value by 2 and then store the result back into another variable A.
Programs is just collections of many such statements, which together describe all the steps so it takes to perform you R program ' s purpose.
Expression
Statements is made up of one or more expressions. An expression was any reference to variable or value, or a set of variables and values combined with operators. For example a= b*2; This statement have four expressions in it:
2 is a literal value expression, B was a variable expression, which means to retrieve it current value
B*2 is a arithmetic expression, which means to do the multiplication.
A = B assignment expression, which means to assign the result of the b * * to the variable A.
A general expression of that stands alone was also called an expression statement, such as the following:b; This flavor of expression statement are not very common or useful, as generally it would not has any effect on the running Of the Program–it would retrieve the current value of B and multiply it by 2, but then wouldn ' t do anything with that Result.
A more common expression statement are a call expression statement, as the entire statement are the function call expression Itself:alert ("a");
Executing a program
How does those collections of programming statements tell the computer? The program needs to is executed, also referred to as running the program.
Statement like a = b*2 is helpful for developers when reading and writing, but is not acturally in a form the computer can directly understand. So a special utility in the computer (either an interpreter or a complier) are used to translate the code you write into CO Mmands a computer can understand.
For some computer languages, this translation of commands was typically done from top to bottom, line by line, every time t He program was run, which is usually called interpreting the code.
For other languages, the translation is do ahead of time, called compiling the code, so when the program runs later, WHA T ' s running is actually the already complied computer instructions ready to go.
It's typically asserted that JavaScript was interpreted, because your JavaScript source code is processed each time it ' s RU N. But the ' s not entirely accurate. The JavaScript engine actually compiles the program in the fly and then immediately runs the compiled code.
Note: To type multiple lines into the console at once, use <shift> + <enter> to move to the nextnew line. Once you hits <enter> by itself, the console would run everything you ' ve just typed.
Value and type
When you express the values in a program, the choose different representations for those the values based on the what's plan to do W ith them. These different representations for values is called types in programming terminology.
When you need to do math, you want a number.
When you need to print a value on the screens, you need a string.
When you need the decision in your program, you need a Boolean.
Converting between Types
If you had a number but need to print it on the screen, you need to convert the value to a string. Similarly, if someone enters a series of numeric characters into a form, that's string, but if you need to then use that V Alue to does math operations, you need to coerce it to a number. Explicit coerceion and implicit coercion
Code Comment
Variables
Most useful programs need to track a value as it changes over the course of the program, undergoing different operations a s called for by your program ' s intended tasks.
The easiest-on-the-go-to-your-is-assign a value to a symbolic container called a variables----so Called because the value in this container can vary over time as needed. The variable holds a running value that changes over the course of the program, illustrating the primary purpose of VARIAB Les:managing program state.
In other words, the tracking of the changes to values as your program runs.
Another common usage of variables is for centralizing value setting. Typically called constants when you declare a variable with a value and intend for that value Throughout the program.
You declare these constants, often at the top of a program, so that it's convenient for your to has one place to go to Alt Er a value if you need to. By convention, JavaScript variables as constants is usually capitalized, with underscores _ between multiple words, such as var tax_rate = 0.08;
Conditions Conditional statement/loop Loop statement = + block (statement block) + Scope
We often need to group a series of statements together and which we often call a block.
{ = a. = Amount; Console.log (amount);}
This kind of standalone {:} general block was valid but was not commonly seen in Js programs. Typically, blocks is attached to some and other control statement, such as an if statement or a loop.
Closure
You can think of closure as a by-remember and continue to access a function ' s scope (its variables) even once the fun Ction has finished running.
function Makeadder (x) { function Add (y) { return x + y; } return var plusone = Makeadder (1); // PlusOne gets a reference to the inner "add (..)" function with closure over the ' x ' parameter of the outer "makeadder (..) " PlusOne (3) // 4
The reference to add (..) function This gets returned with the outer makeadder (...) are able to remember Whatev Er x value is passed in to Makeadder (...)
When we call Makeadder (1), we get back a reference to its inner add (..) That remember X as 1. We Call this function reference PlusOne (...);
When we call PlusOne (3), it adds 3 (its inner y) to the 1 (remembered by X) and we get 4 as the result.
You don ' t know JS--up &going notes