In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains the "javascript data type basic sample code analysis", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "javascript data type basic sample code analysis"!
Input and output statement method in js description of ownership alert (msg) browser pop-up warning box browser console.log (msg) browser console printout information browser prompt (info) browser pop-up input box, the user can enter the browser
Note: the input obtained by prompt (info) is of a string type, similar to input () in python.
Prompt ("Please enter:"); alert ('Hello! Cutie!') ; console.log ('A Niu is the most handsome!')
Comments in js single-line comments multiline comments / / * * /
Note: the comment in css is / * /, it doesn't matter if you can't remember the comments in various languages, as long as you remember the shortcut key ctrl + /, most editors support this shortcut key, which is applicable to most languages, as long as you select the content to be commented out, ctrl + /.
Name variable 1 in js, js declare a variable / / declare variable var age with the keyword var; / / declare a variable named age age = 18; var name = 'aniu' / / initialization of variable
Var is a JS keyword that is used to declare variables (meaning variable variables). After you declare a variable using this keyword, the computer automatically allocates memory space for the variable without programmer control.
Age is the variable name defined by the programmer. We use the variable name to access the space allocated in memory.
2. Declare variable special case description result var age; console.log (age); only declare no assignment undefinedconsole.log (age); do not declare no assignment directly use error report age = 10; console.log (age); do not declare only assignment 103, variable naming convention
It consists of letters (A-Za-z), numbers (0-9), underscores (_), and dollar signs ($), such as usrAge, num01,_ name.
Strictly case-sensitive. Var app; and var App; are two variables.
You cannot start with a number. 18age is wrong.
Cannot be keywords, reserved words. For example: var, for, while
The variable name must be meaningful.
Follow the hump naming method. The first letter is lowercase, and the first letter of the following word needs to be capitalized. MyName
Basic data types in js
Variables are where values are stored, and they have names and data types. The data type of the variable determines how the bits that represent these values are stored in the computer's memory. JavaScript is a weakly typed or dynamic language. This means that there is no need to declare the type of the variable in advance, and the type is determined automatically while the program is running.
Var age = 18; I / / this is a numeric var ok = 'Yes; / / this is a string
When the code is running, the data type of the variable is determined by the JS engine based on the data type of the value of the variable on the right side of =. After running, the variable determines the data type.
Simple data type description default value Number numeric type, including integer value and floating point value, such as 12, 0.820Boolean Boolean value types, such as true, false, equivalent to 1 and 0falseString string types, such as "Zhang San" note that the string in js is in quotation marks "" Undefinedvar a; the variable an is declared but no value is given, a = undefinedundefinedNullvar a = nul, and the variable an is declared as null null numeric Number
Digital base system
The most common bases are binary, octal, decimal, and hexadecimal.
/ / Octal number sequence range: 0,7 var num1=07; / / corresponding to decimal 7 var num2=018; / / corresponding to decimal 18 var num3=08; / / corresponding to decimal 8 / / hexadecimal sequence range: 0binary 9 and A ~ F var num = 0xA; / / corresponding to decimal 10
We just need to remember to add 0 before octal and 0x before hexadecimal in js.
Digital range
1, the maximum and minimum values in JavaScript.
Console.log (Number.MAX_VALUE); / / 1.7976931348623157e+308 console.log (Number.MIN_VALUE); / / 5e-324
Maximum value: Number. MAX_VALUE, this value is 1.7976931348623157e+308
Minimum value: Number. MIN_VALUE, this value is: 5e-32
2, infinitesimal, infinity, non-numeric.
Console.log (Number.MAX_VALUE * 2); / / Infinity infinitesimal console.log (- Number.MAX_VALUE * 2); / /-Infinity infinitesimal console.log ('aniu'-100); / / NaN non-numeric Not a Number / / isNaN () this method is used to determine a non-numeric value and return a value if the number returns false, if not the number returns true console.log (isNaN (12)) / / false console.log (isNaN ('aniu')); / / true
Boolean type Boolean
Such as true, false, equivalent to 1 and 0
Var flag = true; var flag1 = false; console.log (flag); console.log (flag1)
String type String
Escape string in js
Other knowledge points of the string.
Multiple strings can be concatenated using +, which is a new string after concatenation of string + any type =. Before concatenation, any type added to the string is converted into a string and then concatenated into a new string.
/ / 1. Find the length of the string var str ='a niu'; console.log (str.length); / / length method to find the length of the string / / 2. Concatenation of strings + console.log ('aniu'+'a'); / / aniua console.log (' 11 characters 13); / / 1113 var flag = true; var flag1 = false; console.log (flag+1); / / 2 console.log (flag1+1); / / 1 var s = undefined; console.log (s + 'aniu'); / / underfinedaniu console.log (s + 1); / / undefined and numbers add up, resulting in NaN
Undefined and Null
A variable that is not assigned after declaration will have a default value of undefined (if concatenated or correlated, pay attention to the result)
Var m; console.log (m); / / undefined console.log ('A Niu'+ m); / / A Niu undefined console.log (11cm); / / NaN console.log (true + m); / / NaN
A declaration variable is given to the null value, and the value stored in it is empty (while learning the object, we continue to study null)
Var m = null;console.log (m); / / nullconsole.log ('A Niu'+ m); / / A Niu nullconsole.log (11cm); / / 11console.log (true + m); / / 1
Thank you for reading, the above is the content of "javascript data type basic sample code analysis". After the study of this article, I believe you have a deeper understanding of the problem of javascript data type basic sample code analysis, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.