Case Sensitivity, Spaces, and Line Breaks
JavaScript is a case-sensitive language, meaning that uppercase and lowercase letters are distinct. This affects variable names, function names, and other identifiers. Spaces and line breaks are generally insignificant in JavaScript unless used within certain constructs like strings or regular expressions.
Comments
Comments in JavaScript help improve code readability and provide explanatory notes. They are ignored by the JavaScript engine when executing the code. Comments can be single-line (using //
) or multi-line (using /* ... */
).
1
2
3
4
5
6
// This is a single-line comment
/*
This is a multi-line comment
spanning multiple lines
*/
Literals
Literals are notation for representing fixed values directly in JavaScript code. Some common types of literals include:
- Numeric literals:
42
,3.14
,-7
- String literals:
"Hello, world!"
,'JavaScript is fun'
- Boolean literals:
true
,false
- Object literals:
{ key1: value1, key2: value2 }
- Array literals:
[item1, item2, item3]
Identifiers and Reserved Words
Identifiers are names used to identify variables, functions, or properties. They must follow certain rules, such as starting with a letter, underscore, or dollar sign, and can contain letters, digits, underscores, and dollar signs. However, they cannot be reserved words, which have special meanings in JavaScript.
Unicode
JavaScript uses Unicode character encoding, allowing it to handle a wide range of characters from different writing systems. Unicode escape sequences (\uXXXX
) can be used to represent characters outside the basic ASCII range.
1
const snowman = "\u2603"; // Unicode for snowman character β
Optional Semicolons
JavaScript uses semicolons to separate statements, but they are often optional. The JavaScript engine automatically inserts semicolons in certain cases to separate statements. However, itβs considered good practice to include semicolons explicitly to avoid any potential issues.
1
2
3
4
const x = 42; // Semicolon used explicitly
const y = 3
console.log(x + y); // Semicolon automatically inserted here
Remember to explore the comprehensive details and examples provided in the book for a deeper understanding of these concepts. Enjoy your JavaScript journey! ππ
Note: The illustrations and code snippets provided in this summary are for explanatory purposes and may not represent complete code samples. Please refer to the book for more comprehensive examples.