JavaScript Basics (1)_Basic Knowledge
Basics
Javascript: 1. Data types and values
javascript: allows the use of 3 basic types of data----numbers, Strings and Boolean values. In addition, it also supports two small data types, null (empty) and undefined (undefined).
Javascript: It also supports the data type-object (object). There are two types of objects in JavaScript, one An object represents an unordered collection of named values, and the other represents an ordered collection of numbered values. In fact, an ordered collection is an array (Array).
javascript: It also defines another special object - function, and some special objects defined by javascript (the same concept as the C# encapsulated class, just use it directly)
<script> <br>Integer direct quantity: 3 or 10000, to put it bluntly, it is a number <br>Floating point literals: 3.14, 2345.567, etc., which are the ones with a decimal point. <br>String literals: "3.14", "demo", etc., the so-called strings are Unicode enclosed in single or double quotes. character sequence. <br>Convert the number to a string: 1, var s = 100; s ="What you name"; The number will be <br> converted into a string first <br>2, var s = 100 ""; add one Empty string <br> 3. To convert the number into a string more clearly, you can use the String() function or <br> or use the toString function. <br>Convert a string into a number: var product = "2" * "2"; In fact, when a string is used in a numeric environment <br> it will automatically be converted into a number, or it can be subtracted by 0 The same effect can be achieved, or you can use the <br>Number() function <br>Boolean value: <br>What I want to share with you here is conversion: it will be used more in the future. 1. When a Boolean value is used in a numeric environment, true is converted to the number 1, and false is converted to the number 0. In a string environment, true is converted to the string true, and false is converted to the string false <br>Function: <br>A function is an executable JavaScript code segment. Let me talk about it here: As a data type, functions can also be assigned to the properties of objects like other types. When the assignment is successful, the properties are often regarded as references to which methods. Commonly used later. <br>Function direct quantity: var square = function(x){return x*x};//It will be used frequently later and must be understood or remembered<br></script>
Javascript: 2. Object
1. Object
< ;script>
var o = new Object();//Attention everyone, javascript is case sensitive!
var now = new Date()
var regex = new RegExp("^ ?d{1}d{3}$")//Direct quantity of regular expression
object:
var point = {x:12,y:34};
var point2 = {"super":{day:sunday,day1:monday}}//The properties of the object refer to another object.
Conversion of objects:
When a non-empty object is used in a Boolean environment: it is converted to true. When used in a string environment, JavaScript will call the toString() method of the object and use this function The returned value, when used in a numeric environment: JavaScript will call the valueOf() method of the object. If a basic type is returned, this value will be used. Most of the time, the object itself is returned. In this case The JavaScript callback calls the toString() method to convert the object into a string, and then attempts to convert it into a number. I hope everyone will understand the concepts above and use them in the future.
2. Array
<script> <br>var array = new Array(); <br>var arr = new Array(1.2,"Javascript",{x:12,y:23})// <br>Array literal with parameters: <br>var a = [1.2,"Javascript",{x:12,y:23}]//The array is numbered [] and the object is numbered {}, which is easy to remember ! <br></script>
3. Null (empty)
The JavaScript keyword Null is a special value, which means no value. Null is often regarded as a special value of the object type, which means a value without an object. When a variable The value of
is null, then it means that its value is not valid (Array, Object, number, string, Boolean value), details: null is converted to false in a Boolean environment; in a number
environment Convert to 0.
4. Undefined (undefined)
When using an undeclared variable, or using a declared variable but without assigning a value, or using an object property that does not exist, The returned
is the undefined value. In the future (namespaces and modules are still used a lot, everyone needs to understand), details: underfined will be converted to false in the Boolean environment, and it will be converted to false in the digital environment
into NaN. This is different from null. The object encapsulating it is Error.
Summary: Although the above content can be understood at a glance, I hope friends who are beginners like me will not be careless!
JavaScript Basics (2)
Basics
javascript: Declaration of variables
The following are several ways to declare variables
var value;
var value,value1,value2;//Declare multiple variables at the same time, but the values of these variables are all undefined
var i = 0,j = 0,k=100;/ /Variable declaration and initialization integrated.
//If you try to read a variable (value) that does not exist, an error will be reported! But if you try to assign a value to a variable that is not declared using Var, javascript
// will implicitly declare the variable, and the declared variable is still global. Details: So when everyone creates variables, try to use Var
//The scope of the variable (this problem is also easy to happen, everyone needs to understand it)
javascript: The scope of the variable
These It’s all details, and beginners like me must pay attention to avoid it!
var golbal = "golbal"; //global variable
var local = "local";
function area()
{
//The priority of local variables is higher than that of global variables
var local = "arealocal"
//When When the variable name declared in the function body is the same as the global variable name, JavaScript will hide the global variable
var golbal ="areagolbal";
document.write("local is :" local "and golbal is :" golbal "< br />");
}
area();
//Output: local is :arealocaland golbal is :areagolbal
Define local in nested functions variables, what will be the effect? Look below:
var hope = "moremoney";
function createmore()
{
var hope = "have more money";//Partial
function createmoreto()//Nested function
{
var hope = "have more money to much";//Partial
document.write("Createmoreto hope is :" hope "
");
//Output:Createmoreto hope is :have more money to much
}
createmoreto();//Call
document.write("Createmore hope is :" hope "
");
//Output: Createmore hope is :have more money
}
createmore(); //Call
javascript: passing by value and passing by address
This is also an important concept! Don't miss it.
Pass by value and address
Copy the actual copied value , there are different ones. What is copied is only the reference to the number. If passed this
independent copy. The new reference modifies the value, and this change is visible to the original reference as well.
What is passed to the function is an independent copy of the value. What is passed to the function is a reference to the value. If the function
changes it, it has no effect outside the function. If the value is modified by the reference passed to it, this change
Changes are also visible.
Comparison Compares these two opposing values, usually comparing two references one by one to determine whether the
bytes they refer to are compared to determine whether they are equal to the same value.
javascript: basic types and reference types
The basic rules of javascript are: basic types are operated by passing by value, and reference types are operated by passing by address. (What is the value type, or what is the reference, please see my previous article)
Pass by value
var value = 1;
var copyvalue = value; //Assign value to another variable
function addTotal(total,arg)
{
total = arg; //total = total arg has the same effect as
}
//Call the function and pass two parameters (you may think that this function changes the value of the global variable, but in fact it does not. The function also uses opposite copy )
addTotal(value,copyvalue);
if(value == 1) copyvalue = 2;
document.write("total t" value "and copyvalue tt" copyvalue "
");
//Final output: total 1and copyvalue 2
Pass-by-address
var array = new Array("Javascccp");
var objarray = array;
function modifyArray(arr)
{
arr [0] = "JAVASCRIPT";
}
//Before calling the function
document.write(array[0] "
");
//Output Javascccp;
//After calling the function
modifyArray(array);
document.write(array[0] "
");
//Output uppercase JAVASCRIPT
// The same effect will be achieved by modifying objarray
objarray[0] = "Frank";
document.write(array[0] "
");
//Output Frank;
Summary: I hope everyone will not miss the above content, it is still very helpful for learning the following knowledge!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to use WebSocket and JavaScript to implement an online speech recognition system Introduction: With the continuous development of technology, speech recognition technology has become an important part of the field of artificial intelligence. The online speech recognition system based on WebSocket and JavaScript has the characteristics of low latency, real-time and cross-platform, and has become a widely used solution. This article will introduce how to use WebSocket and JavaScript to implement an online speech recognition system.

WebSocket and JavaScript: Key technologies for realizing real-time monitoring systems Introduction: With the rapid development of Internet technology, real-time monitoring systems have been widely used in various fields. One of the key technologies to achieve real-time monitoring is the combination of WebSocket and JavaScript. This article will introduce the application of WebSocket and JavaScript in real-time monitoring systems, give code examples, and explain their implementation principles in detail. 1. WebSocket technology

Introduction to how to use JavaScript and WebSocket to implement a real-time online ordering system: With the popularity of the Internet and the advancement of technology, more and more restaurants have begun to provide online ordering services. In order to implement a real-time online ordering system, we can use JavaScript and WebSocket technology. WebSocket is a full-duplex communication protocol based on the TCP protocol, which can realize real-time two-way communication between the client and the server. In the real-time online ordering system, when the user selects dishes and places an order

How to use WebSocket and JavaScript to implement an online reservation system. In today's digital era, more and more businesses and services need to provide online reservation functions. It is crucial to implement an efficient and real-time online reservation system. This article will introduce how to use WebSocket and JavaScript to implement an online reservation system, and provide specific code examples. 1. What is WebSocket? WebSocket is a full-duplex method on a single TCP connection.

JavaScript and WebSocket: Building an efficient real-time weather forecast system Introduction: Today, the accuracy of weather forecasts is of great significance to daily life and decision-making. As technology develops, we can provide more accurate and reliable weather forecasts by obtaining weather data in real time. In this article, we will learn how to use JavaScript and WebSocket technology to build an efficient real-time weather forecast system. This article will demonstrate the implementation process through specific code examples. We

Usage: In JavaScript, the insertBefore() method is used to insert a new node in the DOM tree. This method requires two parameters: the new node to be inserted and the reference node (that is, the node where the new node will be inserted).

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest

JavaScript is a programming language widely used in web development, while WebSocket is a network protocol used for real-time communication. Combining the powerful functions of the two, we can create an efficient real-time image processing system. This article will introduce how to implement this system using JavaScript and WebSocket, and provide specific code examples. First, we need to clarify the requirements and goals of the real-time image processing system. Suppose we have a camera device that can collect real-time image data
