2023-08-08 01:41:11
Naming rules JavaScript naming rules are very important, it has some specific conventions and restrictions. For example, variables and functions are often named using lower camel case (firstName). JavaScript is then case sensitive, so lastName and lastname are different variables. Comments can be single-line comments // or multi-line comments /* */. Data type The basic data type of JavaScript, including boolean (true/false), empty (null), undefined (undefined), value (number), string (string) and object (Object). Objects are composite data types. For example, Array is a subtype of Object.There are also some special values like empty array[]and NaN (Not a Number). Objects and arrays Objects and arrays are commonly used data structures in JavaScript. Objects are defined using and can have properties and methods. For example: This object has three properties: title, author and pages, and a method read. var book = title: “My first book”, author: “Xiao Ming”, pages: 100, read: function() return “You are reading” + this.title + “by” + this.author + “Written.”; ;console.log(book.read()); Arrays use square brackets[]To define, multiple values can be stored. For example: This array has three elements which can be accessed by index 0, 1 and 2. var fruits = [“蘋果”, “香蕉”, “橙子”];console.log(fruits[0]); console.log(fruits[1]); console.log(fruits[2]);
1691459301
#Frontend #study #notes #JavaScript #naming #rules #data #types #objects #arrays