finds an HTML element : document.getElementById('demo')
Writing into an HTML element : innerHTML
Writing into the HTML output : document.write();
Writing into an alert box : window.alert(); or alert();
Writing into the browser console : console.log();
the browser to print the content of the current window : window.print()
KeywordDescription
var | Declares a variable |
let | Declares a block variable |
const | Declares a block constant |
if | Marks a block of statements to be executed on a condition |
switch | Marks a block of statements to be executed in different cases |
for | Marks a block of statements to be executed in a loop |
function | Declares a function |
return | Exits a function |
try | Implements error handling to a block of statements |
Hyphens are not allowed in JavaScript
Underscore, Upper Camel Case (Pascal Case), Lower Camel Case
The var keyword was used in all JavaScript code from 1995 to 2015.
The let and const keywords were added to JavaScript in 2015.
const if the value should not be changed
Block Scope(let) , Global Scope (var)
let
inside a { } block cannot be accessed from outside the block
can not be redeclared
var
inside a { } block can be accessed from outside the block
can be redeclared
Scope | Redeclare | Reassign | Hoisted | Binds this | |
var | No | Yes | Yes | Yes | Yes |
let | Yes | No | Yes | No | No |
const | Yes | No | No | No | No |
JavaScript Object(Objects, Properties, Methods, Display, Constructors)
create : ex) const person = {}; or const person = new Object();
add : ex) person.nationalisy = "";
Accessing Object Properties
objectName.propertyName or objectName["propertyName"]
nested Objects : objectName["propertyName"] . ["propertyName1"] or objectName.propertyName.propertyName1
Deleting Properties
delete person.age; or delete person["age"];
Accessing Object Methods
objectName.methodName()
Adding a Method to an Object
person.name = function () {
return this.firstName + " " + this.lastName;
};
'JAVASCRIPT' 카테고리의 다른 글
20241122_1 Date Objects (0) | 2024.11.22 |
---|---|
20241121_2 Arrays (0) | 2024.11.21 |
20241121_1 Numbers (2) | 2024.11.21 |
20241120_ String (Methods,Templates) (0) | 2024.11.20 |
20241120_2 기초2 (2) | 2024.11.20 |