Jun 27, 2024
index.html
, style.css
, index.js
.! + tab
in VS Code to auto-generate HTML structure.index.html
.
<link rel="stylesheet" href="style.css">
<script src="index.js"></script>
<h1>Hello</h1>
<p>Lorem ipsum...</p>
body { font-family: Verdana; font-size: 2em; }
<link>
tag in the <head>
section.console.log('Hello');
to check values in Developer Tools.window.alert('This is an alert');
for basic prompts.// This is a comment.
/* This is a multi-line comment. */
HTML
: Elements to interact with.JavaScript
: Functions to manipulate HTML/CSS.<h1 id="myH1"></h1>
<p id="myP"></p>
document.getElementById('myH1').textContent = 'Hello';
document.getElementById('myP').textContent = 'I like JavaScript!';
let
, const
, var
.
let x = 100;
typeof
keyword.+
, -
, *
, /
, %
(modulus).++
, --
.+=
, -=
, *=
, /=
, %=
(augmented assignment).window.prompt('Enter your age');
Number()
, String()
, Boolean()
const PI = 3.14;
Math.PI
, Math.round()
, Math.ceil()
, etc.Math.random()
method.if (condition) {
// code block
} else if (condition) {
// code block
} else {
// code block
}
&&
, ||
, !
window.prompt()
function functionName(params) { // code }
const functionName = function(params) { // code }
.const greet = (name) => `Hello ${name}`;
let promise = new Promise((resolve, reject) => {
// async code
if (success) resolve('Success!');
else reject('Failure!');
});
promise.then((value) => { // code }).catch((error) => { // code });
async function example() {
let result = await someAsyncOperation();
console.log(result);
}
try {
// code
} catch (error) {
console.log(error);
} finally {
// cleanup code
}
fetch('https://api.weatherapi.com/data').then(response => response.json()).then(data => console.log(data));
.catch()
for handling errors.