js common functions good_basic knowledge
1. Regular functions
JavaScript regular functions include the following 9 functions:
(1) alert function: displays a warning dialog box, including an OK button.
(2)confirm function: Display a confirmation dialog box, including OK and Cancel buttons.
(3)escape function: Convert characters into Unicode codes.
(4) eval function: calculates the result of an expression.
(5) isNaN function: Test whether (true) or not (false) is not a number.
(6)parseFloat function: Convert a string into dotted digital form.
(7)parseInt function: Convert the string into integer digital form (the decimal system can be specified).
(8)prompt function: Display an input dialog box, prompting to wait for user input. For example:
(9)unescape function: Decode characters encoded by the escape function.
2. Array function
JavaScript array function includes the following 4 functions:
(1) join function: convert and connect all elements in the array into a string. Example:
Program code
Function JoinDemo()
{
var a, b;
a = new Array(0,1,2,3,4);
b = a.join("-");//Separator
return(b);//Returned b=="0-1-2-3-4"
}
(2)langth function: Returns the length of the array. Example:
Program code
function LengthDemo()
{
var a, l;
a = new Array(0,1,2,3,4);
l = a.length;
return(l);//l==5
}
(3)reverse function: Reverse the order of array elements. Example:
Program code
function ReverseDemo()
{
var a, l;
a = new Array(0,1,2,3,4);
l = a.reverse();
return(l);
}
(4) Sort function: Reorder array elements. Example:
Program code
function SortDemo()
{
var a, l;
a = new Array("X","y","d", Z", "v","m","r");
l = a.sort();
return(l);
}
3. Date function
javascript The date function includes the following 20 functions:
(1) getDate function: returns the "day" part of the date, with values from 1 to 31. Example:
Program code
function DateDemo()
{
var d, s = "Today's date is: ";
d = new Date();
s = (d.getMonth() 1) "/";
s = d.getDate() "/";
s = d.getYear();
return(s);
}
(2) getDay function: Returns the day of the week, the value is 0~6, where 0 means Sunday, 1 means Monday,..., 6 means Saturday. Example:
Program code
function DateDemo()
{
var d, day, x, s = "Today is: ";
var x = new Array("Sunday ", "Monday", "Tuesday");
var x = x.concat("Wednesday", "Thursday", "Friday");
var x = x.concat("Saturday");
d = new Date();
day = d.getDay();
return(s = x[day]); hour" part, the value is 0~23. example.
Program code
function TimeDemo()
{
var d, s = "The current local time is: ";
var c = ":";
d = new Date();
s = d.getHours() c;
s = d.getMinutes() c;
s = d.getSeconds() c;
s = d.getMilliseconds ();
Return(s);
See the example above.
(5) getMonth function: Returns the "month" part of the date, with a value of 0 to 11. Among them, 0 represents January, 2 represents March, ..., and 11 represents December. See the previous example
.
(6) getSeconds function: Returns the "seconds" part of the date, the value is 0~59. See previous example.
(7)getTime function: Returns the system time.
Program code
function GetTimeTest()
{
var d, s, t;
var MinMilli = 1000 * 60; 🎜> var DyMilli = HrMilli * 24;
d = new Date();
t = d.getTime();
s = "It's been "
s = Math.round(t / DyMilli) " days since 1/1/70";
return(s);
time difference) in minutes.
Program code
function TZDemo()
{
var d, tz, s = "The current local time is ";
d = new Date();
tz = d.getTimezoneOffset();
if (the name of the link point of tz, the URL address set by another function link.
(2) big function: increase the font to size one, and ...The label result is the same. (3) Blink function: Makes the string blink, which is the same as the ... label result.
(4) Bold function: Makes the font bold, which is the same as the ... label result. .
(5) charAt function: Returns a character specified in the string. (6) Fixed function: Sets the font to a fixed-width font, the same as... tag result. 7) Fontcolor function: Set the font color, which is the same as the label result. (8) Fontsize function: Set the font size, which is the same as the label result. (9) IndexOf function: Return the first one in the string. Find the subscript index, starting from the left.
(10)italics function: Make the font italic, the same as... tag result.
(11)lastIndexOf function: return the first one in the string. Find the subscript index, starting from the right.
(12)length function: Return the length of the string (without parentheses)
(13)Link function: Generate a hyperlink, equivalent to setting.
(14) Small function: Reduce the font size by one size, the same result as... tag.
(15) Strike function: Add a horizontal line in the middle of the text, as... .The label result is the same.
(16) Sub function: Display the string as a subscript (17) Substring function: Return the specified characters in the string. sup function: Display the string as superscript. (19) toLowerCase function: Convert the string to lowercase. (20) ToUpperCase function: Convert the string to uppercase.
//Check whether it is all composed of numbers
Program code
function isDigit(s)
{
var patrn=/^[0-9]{1 ,20}$/;
if (!patrn.exec(s)) return false
return true
}
//Verify login name: only 5 can be entered -20 strings starting with letters and can contain numbers, "_", "."
Program code
function isRegisterUserName(s)
{
var patrn=/^[ a-zA-Z]{1}([a-zA-Z0-9]|[._]){4,19}$/;
if (!patrn.exec(s)) return false
return true
}
//Verify user name: Only 1-30 strings starting with letters can be entered
Program code
function isTrueName( s)
{
var patrn=/^[a-zA-Z]{1,30}$/;
if (!patrn.exec(s)) return false
return true
}
//Verification password: only 6-20 letters, numbers, and underscores can be entered
Program code
function isPasswd(s)
{
var patrn=/^(w){6,20}$/;
if (!patrn.exec(s)) return false
return true
}
/ /Verify ordinary telephone and fax numbers: It can start with " ", and in addition to numbers, it can contain "-"
Program code
function isTel(s)
{
//var patrn =/^[ ]{0,1}(d){1,3}[ ]?([-]?(d){1,12}) $/;
var patrn=/^[ ]{0 ,1}(d){1,3}[ ]?([-]?((d)|[ ]){1,12}) $/;
if (!patrn.exec(s)) return false
return true
}
//Verify mobile phone number: must start with a number. In addition to numbers, it can contain "-"
Program code
function isMobil(s)
{
var patrn=/^[ ]{0,1}(d){1,3}[ ]?([-]?((d)|[ ]){ 1,12}) $/;
if (!patrn.exec(s)) return false
return true
}
//Verify postal code
Program code
function isPostalCode(s)
{
//var patrn=/^[a-zA-Z0-9]{3,12}$/;
var patrn=/^[ a-zA-Z0-9 ]{3,12}$/;
if (!patrn.exec(s)) return false
return true
}
//Verification Search keywords
Program code
function isSearch(s)
{
var patrn=/^[^`~!@#$%^&*() =|\][ ]{}:;',./?]{1}[^`~!@$%^&() =|\][]{}:;',.?]{0, 19}$/;
if (!patrn.exec(s)) return false
return true
}
Program code
function isIP(s) // by zergling
{
var patrn=/^[0-9.]{1,20}$/;
if (!patrn.exec(s)) return false
return true
}

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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











JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

The latest trends in JavaScript include the rise of TypeScript, the popularity of modern frameworks and libraries, and the application of WebAssembly. Future prospects cover more powerful type systems, the development of server-side JavaScript, the expansion of artificial intelligence and machine learning, and the potential of IoT and edge computing.

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

JavaScript is the core language of modern web development and is widely used for its diversity and flexibility. 1) Front-end development: build dynamic web pages and single-page applications through DOM operations and modern frameworks (such as React, Vue.js, Angular). 2) Server-side development: Node.js uses a non-blocking I/O model to handle high concurrency and real-time applications. 3) Mobile and desktop application development: cross-platform development is realized through ReactNative and Electron to improve development efficiency.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

This article demonstrates frontend integration with a backend secured by Permit, building a functional EdTech SaaS application using Next.js. The frontend fetches user permissions to control UI visibility and ensures API requests adhere to role-base

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

JavaScript does not require installation because it is already built into modern browsers. You just need a text editor and a browser to get started. 1) In the browser environment, run it by embedding the HTML file through tags. 2) In the Node.js environment, after downloading and installing Node.js, run the JavaScript file through the command line.
