


Explicit conversion and implicit conversion based on javascript (detailed explanation)_javascript skills
The following editor will share with you an article based on javascript explicit conversion and implicit conversion (detailed explanation), and also provides JavaScript source code! , if you are interested in JavaScript, please follow the editor to have a look
Display conversion
1 .Title: Please enter your age this year. How old will you be in 5 years?
//a.prompt接收到的数据是string类型的。 var age = prompt("请输入你今年的年龄"); alert(typeof age); var age5 = age + 5; // 这里只会拼接成了15,而不是加5 alert("我今年"+age+"岁了,5年后我"+age5+"岁了");
2.String needs to be converted into number type.
In response to the above problem, age needs to be converted into a numeric type
2.1 You can use Number (the content that needs to be converted);
var str = true; var num = Number(str); console.log(num); //1 console.log(typeof num); //number // 注意: // 1.如果这个转换的字符串本身就是一个数字,那么可以转换成功; 如果这个字符串本身不是一个数字,那么转成NaN. // 2.如果这个字符串本身是一个数字,前后有空格,也是会转换成功的; 如果中间有空格,就转成NaN. // 3.如果是一个"",或者是" ",或者是flase,那么会转换成0.true转成1,undefined转成NaN // 4.如果字符串的本身是一个小数,也是可以转换成功的。
2.2 You can use parseInt (required Content to be converted);
var str = "123"; var num = parseInt(str); console.log(num); //123 console.log(typeof num); //number // 注意: // 1.从左往右查找,直到遇到第一个非数字为止,前面的所有的内容转换成数字。 // 2.如果找完了,都没有找到一个数字,那么就转换成NaN. // 3."" 和 " " 转化成NaN // 4.如果字符串里面是小数,那么转换后只能得到他的整数部分。
2.3 You can use parseFloat(content to be converted);
var str = "123.24ll"; var num = parseFloat(str); console.log(num); //123.24 console.log(typeof num); //number // 注意:如果字符串里面是小数,那么转换后还是小数。。 //******注意: true会转成1,false会转换0. // 如果字符串转数字,一般的使用parseInt或者parseFolat。 // 如果是其他类型,比如布尔类型,使用Number();
3. Other types of data are converted into string types.
3.1 You can use String (the content that needs to be converted);
var num = 123; var str = String(num); console.log(str); //"123" console.log(typeof str); //string //注意: "123" "true" "false" "undefined" "null" "NaN"
3.2 You can use the content that needs to be converted.toString();
var num = 123; var str = num.toString(); console.log(str); //"123" console.log(typeof str); //string //注意: "123" "true" "false "NaN" //undefined 和null 不能使用toString。
4 .Other data types are converted into boolean types.
4.1 You can use Boolean (the content that needs to be converted);
var num = ""; var res = Boolean(num); console.log(res); //false console.log(typeof res); //boolean //注意: //那些可以转换成布尔类型的false: 0 -0 false "" undefined null NaN //" "会转换成true
Implicit conversion
1. Other types are converted into number types.
1.1 You can add a positive sign in front of the content that needs to be converted. +
var str = "123"; var res = +str; console.log(res); //123 console.log(typeof res); //number
1.2 The content that needs to be converted can be used for arithmetic operations and cannot be used later. +
var str = "123"; var res = str * 1; console.log(res); //123 console.log(typeof res); //number //注意: 一定要和连接符做一个区分。
2. Other types are converted into string types. Use the connector + ""
var num = 123; var str = num + ""; console.log(str); //"123" console.log(typeof str);//string
3. Other types are converted into boolean types. Use the negation operator
var num = undefined; var res = !!num; console.log(res); //false console.log(typeof res);boolean // 注意:那些能转成布尔类型的false:0 -0 false undefiend null NaN ""
1. Question: Please enter your age this year and find out how old you will be in 5 years.
//a.prompt接收到的数据是string类型的。 var age = +prompt("请输入你今年的年龄"); var age5 = age + 5; alert("我今年"+age+"岁了,5年后我"+age5+"岁了");
The above article based on explicit conversion and implicit conversion (detailed explanation) of javascript is all the content shared by the editor with you. I hope it can give you a reference, and I also hope you can use PHP Chinese website.
Related recommendations:
Use javascript to convert external link styles
HTML TO JavaScript conversion_JavaScript
javaScript mobile phone number verification tool class PhoneUtils detailed explanation
The above is the detailed content of Explicit conversion and implicit conversion based on javascript (detailed explanation)_javascript skills. For more information, please follow other related articles on the PHP Chinese website!

The differences in performance and efficiency between Python and JavaScript are mainly reflected in: 1) As an interpreted language, Python runs slowly but has high development efficiency and is suitable for rapid prototype development; 2) JavaScript is limited to single thread in the browser, but multi-threading and asynchronous I/O can be used to improve performance in Node.js, and both have advantages in actual projects.

JavaScript originated in 1995 and was created by Brandon Ike, and realized the language into C. 1.C language provides high performance and system-level programming capabilities for JavaScript. 2. JavaScript's memory management and performance optimization rely on C language. 3. The cross-platform feature of C language helps JavaScript run efficiently on different operating systems.

JavaScript runs in browsers and Node.js environments and relies on the JavaScript engine to parse and execute code. 1) Generate abstract syntax tree (AST) in the parsing stage; 2) convert AST into bytecode or machine code in the compilation stage; 3) execute the compiled code in the execution stage.

The future trends of Python and JavaScript include: 1. Python will consolidate its position in the fields of scientific computing and AI, 2. JavaScript will promote the development of web technology, 3. Cross-platform development will become a hot topic, and 4. Performance optimization will be the focus. Both will continue to expand application scenarios in their respective fields and make more breakthroughs in performance.

Both Python and JavaScript's choices in development environments are important. 1) Python's development environment includes PyCharm, JupyterNotebook and Anaconda, which are suitable for data science and rapid prototyping. 2) The development environment of JavaScript includes Node.js, VSCode and Webpack, which are suitable for front-end and back-end development. Choosing the right tools according to project needs can improve development efficiency and project success rate.

Yes, the engine core of JavaScript is written in C. 1) The C language provides efficient performance and underlying control, which is suitable for the development of JavaScript engine. 2) Taking the V8 engine as an example, its core is written in C, combining the efficiency and object-oriented characteristics of C. 3) The working principle of the JavaScript engine includes parsing, compiling and execution, and the C language plays a key role in these processes.

JavaScript is at the heart of modern websites because it enhances the interactivity and dynamicity of web pages. 1) It allows to change content without refreshing the page, 2) manipulate web pages through DOMAPI, 3) support complex interactive effects such as animation and drag-and-drop, 4) optimize performance and best practices to improve user experience.

C and JavaScript achieve interoperability through WebAssembly. 1) C code is compiled into WebAssembly module and introduced into JavaScript environment to enhance computing power. 2) In game development, C handles physics engines and graphics rendering, and JavaScript is responsible for game logic and user interface.


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

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Atom editor mac version download
The most popular open source editor

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Zend Studio 13.0.1
Powerful PHP integrated development environment

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function
