Home > Web Front-end > JS Tutorial > Introduction to JavaScript data types, literals, and variables_Basic knowledge

Introduction to JavaScript data types, literals, and variables_Basic knowledge

WBOY
Release: 2016-05-16 17:53:19
Original
1356 people have browsed it
Data type:
1. Numeric type (integer floating point floating point type)
2. String type (string)
3. Boolean type (only two values: true fasle)

String literal
1. Escape series:
Some symbols cannot be identified in JavaScript, and they can only be displayed correctly after escaping. For example:
' Single quotation mark
" Double quotation mark
n Line feed character
r Carriage return character
\ Backslash

Escape example:
Copy code The code is as follows:



Escaped example output:
Copy code The code is as follows:

hello
world (line breaks between hello and world)


2. String splicing

The string splicing operator symbol is the plus sign (). When two strings are spliced, JavaScript will splice them into one string; when a When numbers and a string are spliced, JavaScript will splice them into a string; when two numbers are spliced, the operator will become an addition operator


String splicing example.
Copy code The code is as follows:

document.write("link" "nan"); // Concatenate two strings, output linknan
document.write("5" 100); // Concatenate a number and a string, output 5100
document.write(5 100); // Two Number splicing, output 105


3.typeof operator

is used to determine the data type. 🎜>
Copy code
The code is as follows: docunment.write(typeof(linknan)); // linknan is a character type, output String


Composite data type


1. Variable The value of the variable can be changed. Naming method: the first character must be. Letters or underscores are case-sensitive. Use var to declare variables.
var num = 5; // The variable name is "num" and the value is 5
var num = 5; // Initialized
var num; // Not initialized

When naming, please pay attention to case-sensitivity. Do not use reserved words or names that are too long and difficult to remember; avoid using two similar variable names; in the program Start by declaring all variables.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template