Home >Web Front-end >JS Tutorial >What are the basic data types in js
What are the basic data types in js, specific code examples are required
JavaScript is a programming language widely used in web development. In JavaScript, there are several basic data types, including Number, String, Boolean, Undefined, Null and Symbol. This article walks through each of these data types and provides specific code examples.
var num1 = 10; // 整数 var num2 = 3.14; // 浮点数 console.log(num1); // 输出:10 console.log(num2); // 输出:3.14
var str1 = 'Hello'; // 使用单引号声明字符串 var str2 = "World"; // 使用双引号声明字符串 console.log(str1 + ' ' + str2); // 输出:Hello World
var bool1 = true; // 真 var bool2 = false; // 假 console.log(bool1); // 输出:true console.log(bool2); // 输出:false
var x; // 未定义变量x console.log(x); // 输出:undefined
var y = null; // 变量y的值为空 console.log(y); // 输出:null
var sym = Symbol('foo'); // 创建一个Symbol类型的值 console.log(sym); // 输出:Symbol(foo)
The above are several basic data types in JavaScript and corresponding code examples. Mastering these data types is very important for writing JavaScript programs. I hope this article can be helpful to readers.
The above is the detailed content of What are the basic data types in js. For more information, please follow other related articles on the PHP Chinese website!