1.JavaScript is case sensitive.
JavaScript is sensitive to capitalization.
When writing JavaScript statements, be aware of whether to turn off the case toggle key.
The function getElementById is different from the getElementById.
Similarly, variable myvariable and myvariable are also different.
2. Spaces
JavaScript ignores extra spaces. You can add spaces to the script to improve its readability. The following two lines of code are equivalent:
var name= "Hello"; var name = "Hello";
3. Wrapping lines in lines of code
You can wrap lines of code in a text string with backslashes. The following example will display correctly:
document.write ("Hello \world!");
However, you cannot fold a line like this:
document.write \ ("Hello world!");
4.JavaScript variables
Like algebra,JavaScript variables can be used to hold values (such as x=2) and expressions (such as z=x+y).
Variables can use short names (such as x and y), or they can use better descriptive names (such as age , Sum, Totalvolume).
- Variables must start with a letter
- Variables can also start with the $ and _ symbols (but not recommended)
- Variable names are case sensitive (y and y are different variables)
Tip: Both JavaScript statements and JavaScript variables are case-sensitive.
5.JavaScript Data types
JavaScript variables can also hold other data types, such as text values (name= "Bill Gates").
In JavaScript , a text like "Bill Gates" is called a string.
There are many types of JavaScript variables, but for now, we only focus on numbers and strings.
When you assign a text value to a variable, enclose the value in double or single quotation marks.
Do not use quotation marks when the value you assign to a variable is numeric. If you enclose a value in quotation marks, the value is treated as text.
Example
var pi=3.14;var name= "Bill Gates"; var answer= ' Yes I am! ';
6. One statement, multiple variables
You can declare many variables in a single statement. The statement starts with var and separates the variables with commas:
var name= "Gates", age=56, job= "CEO";
Declarations can also span multiple lines:
var name= "Gates", age=56,job= "CEO";
7.Value = undefined
In computer programs, variables that are not valued are often declared. A variable that is not declared with a value, whose value is actually undefined.
After the following statement has been executed, the value of the variable carname will be undefined:
var carname;
8. Re-declare JavaScript variables
If you re-declare a JavaScript variable, the value of the variable is not lost:
After the following two statements are executed, the value of the variable carname remains "Volvo":
var carname= "Volvo"; var carname;
9.JavaScript has a dynamic type
JavaScript has a dynamic type. This means that the same variables can be used for different types:
Instance
var x//x is undefinedvar x = 6; X is the number var x = "Bill"; X is a string
10.JavaScript Digital
JavaScript has only one numeric type. Numbers can be with decimal points or without:
Instance
var x1=34.00; use the decimal point to write var x2=34; do not use the decimal point to write
Large or small numbers can be written by means of scientific (exponential) notation:
Instance
var y=123e5; 12300000var z=123e-5; 0.00123
11.JavaScript string
A string is a variable that stores characters, such as Bill Gates.
The string can be any text in quotation marks. You can use single or double quotation marks:
Instance
var carname= "Bill Gates"; var carname= ' Bill Gates ';
You can use quotation marks in a string, as long as you do not match the quotes enclosing the string:
12.JavaScript arrays
The following code creates an array named cars :
var cars=new Array (); cars[0]= "Audi"; cars[1]= "BMW"; cars[2]= "Volvo";
or (condensed array):
var cars=new Array ("Audi", "BMW", "Volvo");
or (literal array):
13.JavaScript objects
Objects are separated by curly braces. Inside the parentheses, the properties of the object are defined in the form of name and value pairs (name:value) . Attributes are separated by commas:
var person={firstname: "Bill", LastName: "Gates", id:5566};
The object (person) in the example above has three attributes:firstname,lastname , and ID .
Spaces and lines do not matter. Declarations can span multiple lines:
var person={firstname: "Bill", LastName: "Gates", id:5566};
Object properties are addressed in two ways:
Instance
name=person.lastname;name=person["LastName"];
14.Undefined and Null
Undefined This value indicates that the variable does not contain a value.
You can empty a variable by setting the value of the variable to null .
15. Declaring Variable types
When you declare a new variable, you can use the keyword "new" to declare its type:
var carname=new string;var x= New Number;var y= new Boolean;var cars= new Array;var person= new Object;
JavaScript variables are objects. When you declare a variable, a new object is created.
Note: All of the above are W3school study income
JavaScript Novice Learning Notes (i)