<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title>js 基礎(chǔ)</title> <script type="text/css" src="xxx.js"></script> <!--外鏈?zhǔn)?--> </head> <body> <p onclick="alert('我是行內(nèi)式')">你好</p> <script type="text/javascript"> //內(nèi)嵌式 // 輸出語(yǔ)句 alert("我是內(nèi)嵌式"); prompt("請(qǐng)輸入:"); confirm("你好嗎?"); console.log("我是控制臺(tái)輸出"); console.error("我是錯(cuò)誤");//了解 console.warn("我是警告");//了解 document.write("<h1>我是h1標(biāo)簽</h1>");//頁(yè)面輸出內(nèi)容而且識(shí)別標(biāo)簽 //數(shù)據(jù)類(lèi)型 var str1 = "aa"; var str2 = "123"; var num = 123; var bool = true; //true false var kong =null; var wu ; //undefined 未定義 //查看數(shù)據(jù)類(lèi)型 (typeof 變量 ) var type = typeof(str1); //類(lèi)型轉(zhuǎn)換 成數(shù)字number var str = "123.2a";//字符串類(lèi)型的數(shù)字 var bool = true; var num1 = parseInt(str); //取第一部分?jǐn)?shù)字 并取整 沒(méi)有數(shù)字Nan 輸出:123 var num2 = parseFloat(str); //取第一部分?jǐn)?shù)字 保留小數(shù) 輸出:123.2 var num3 = Number(str); //有非數(shù)字就會(huì)報(bào) Nan 沒(méi)有就全部轉(zhuǎn)換成數(shù)字 console.log(typeof Number(bool)); //boolean 轉(zhuǎn)成1 console.log(typeof (str-0)); //數(shù)子類(lèi)型的字符串在處"+"外都會(huì)有隱士類(lèi)型轉(zhuǎn)換 console.log(typeof (bool-0)); console.log(typeof (str*1)); console.log(typeof (bool*1)); console.log(typeof (str/1)); console.log(typeof (bool/1)); console.log(typeof typeof (bool/1)); //數(shù)據(jù)類(lèi)型是用string定義的 //類(lèi)型轉(zhuǎn)換 成字符串String var num4 = 123; var num5 = num+""; //"+"在有字符串在于運(yùn)算的時(shí)候表示拼接 而非相加 var num6 = num.toString(); var num7 = String(num2); console.log(typeof num5); //進(jìn)制轉(zhuǎn)換 var num8 = parseInt(111,2); //任意進(jìn)制轉(zhuǎn)換成十進(jìn)制。111:值,2:進(jìn)制 輸出:7 var num = 10; var renyi = num.toString(16); //十進(jìn)制轉(zhuǎn)換成任意進(jìn)制 輸出:a //特殊的 undefined 和 null console.log(undefined == null); //true console.log(undefined === null); //false console.log(undefined+10); // Nan 不是一個(gè)數(shù)字 console.log(null+10); //10 //操作符種類(lèi) 一,算數(shù)運(yùn)算符(+—*/...) a) 一元運(yùn)算符:正號(hào),負(fù)號(hào),++,--,平方等一個(gè)變量就能運(yùn)算 b) 二元運(yùn)算符:+-*/%等兩個(gè)變量才能運(yùn)算 c) 三元運(yùn)算符: 值1?值2:值3; 二,邏輯運(yùn)算符( ||&& ! )(或且非) 三,比較運(yùn)算符(<,>,==,>=...) 四,賦值運(yùn)算符(=,+=,-=,*=,/=,%=) //優(yōu)先級(jí) 1 () 2 !,-(負(fù)數(shù)),++,-- (正數(shù)省略+)(一元運(yùn)算) 3 *,/,% 4 +,- (加,減)(二元運(yùn)算) 5 <,<=,<,>= (一級(jí)邏輯運(yùn)算) 6 ==,!=,===,!==, (二級(jí)邏輯運(yùn)算) 7 && (三級(jí)級(jí)邏輯運(yùn)算) 8 || 9 ?: (三元運(yùn)算) 10 =,+=,-=,*=,/=,%= (賦值運(yùn)算) // && 和 || 運(yùn)算 一 && 鏈接兩個(gè)boolean類(lèi)型,有一個(gè)是false結(jié)果就是false, A與B 都是true取后面,都是false取前面 二 || 鏈接兩個(gè)boolean類(lèi)型,有一個(gè)是true結(jié)果就是true, A或B 都是true取前面,都是false取后面 </script> </body> </html>
This article explains the basic data types and conversion base operators of js. For more related content, please pay attention to the PHP Chinese website.
Related recommendations:
The above is the detailed content of js basic data types and conversion base operators. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

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

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

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

Face detection and recognition technology is already a relatively mature and widely used technology. Currently, the most widely used Internet application language is JS. Implementing face detection and recognition on the Web front-end has advantages and disadvantages compared to back-end face recognition. Advantages include reducing network interaction and real-time recognition, which greatly shortens user waiting time and improves user experience; disadvantages include: being limited by model size, the accuracy is also limited. How to use js to implement face detection on the web? In order to implement face recognition on the Web, you need to be familiar with related programming languages ??and technologies, such as JavaScript, HTML, CSS, WebRTC, etc. At the same time, you also need to master relevant computer vision and artificial intelligence technologies. It is worth noting that due to the design of the Web side

How to use PHP and JS to create a stock candle chart. A stock candle chart is a common technical analysis graphic in the stock market. It helps investors understand stocks more intuitively by drawing data such as the opening price, closing price, highest price and lowest price of the stock. price fluctuations. This article will teach you how to create stock candle charts using PHP and JS, with specific code examples. 1. Preparation Before starting, we need to prepare the following environment: 1. A server running PHP 2. A browser that supports HTML5 and Canvas 3

Essential tools for stock analysis: Learn the steps to draw candle charts in PHP and JS. Specific code examples are required. With the rapid development of the Internet and technology, stock trading has become one of the important ways for many investors. Stock analysis is an important part of investor decision-making, and candle charts are widely used in technical analysis. Learning how to draw candle charts using PHP and JS will provide investors with more intuitive information to help them make better decisions. A candlestick chart is a technical chart that displays stock prices in the form of candlesticks. It shows the stock price

How to use JS and Baidu Map to implement map pan function Baidu Map is a widely used map service platform, which is often used in web development to display geographical information, positioning and other functions. This article will introduce how to use JS and Baidu Map API to implement the map pan function, and provide specific code examples. 1. Preparation Before using Baidu Map API, you first need to apply for a developer account on Baidu Map Open Platform (http://lbsyun.baidu.com/) and create an application. Creation completed

How to use JS and Baidu Maps to implement the map heat map function Introduction: With the rapid development of the Internet and mobile devices, maps have become a common application scenario. As a visual display method, heat maps can help us understand the distribution of data more intuitively. This article will introduce how to use JS and Baidu Map API to implement the map heat map function, and provide specific code examples. Preparation work: Before starting, you need to prepare the following items: a Baidu developer account, create an application, and obtain the corresponding AP

Overview of how to use JS and Baidu Maps to implement map click event processing: In web development, it is often necessary to use map functions to display geographical location and geographical information. Click event processing on the map is a commonly used and important part of the map function. This article will introduce how to use JS and Baidu Map API to implement the click event processing function of the map, and give specific code examples. Steps: Import the API file of Baidu Map. First, import the file of Baidu Map API in the HTML file. This can be achieved through the following code:

With the rapid development of Internet finance, stock investment has become the choice of more and more people. In stock trading, candle charts are a commonly used technical analysis method. It can show the changing trend of stock prices and help investors make more accurate decisions. This article will introduce the development skills of PHP and JS, lead readers to understand how to draw stock candle charts, and provide specific code examples. 1. Understanding Stock Candle Charts Before introducing how to draw stock candle charts, we first need to understand what a candle chart is. Candlestick charts were developed by the Japanese

The relationship between js and vue: 1. JS as the cornerstone of Web development; 2. The rise of Vue.js as a front-end framework; 3. The complementary relationship between JS and Vue; 4. The practical application of JS and Vue.
