Dashboard Temp Share Shortlinks Frames API

HTMLify

Full JavaScript
Views: 398 | Author: djdj
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JavaScript Topics with Navigation</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            line-height: 1.6;
            margin: 0;
            padding: 20px;
            color: #333;
        }
        h1, h2 {
            color: #0056b3;
        }
        pre {
            background: #f4f4f4;
            padding: 10px;
            border-left: 5px solid #ccc;
            overflow-x: auto;
        }
        code {
            font-family: "Courier New", monospace;
            color: #c7254e;
        }
        section {
            margin-bottom: 40px;
        }
        a {
            color: #0056b3;
            text-decoration: none;
        }
        a:hover {
            text-decoration: underline;
        }
        nav {
            background: #f0f0f0;
            padding: 20px;
            margin-bottom: 30px;
            border-radius: 8px;
        }
        nav a {
            display: block;
            padding: 10px;
            border-bottom: 1px solid #ddd;
        }
        nav a:last-child {
            border-bottom: none;
        }
        nav a:hover {
            background: #ddd;
        }
        .back-to-top {
            display: block;
            margin-top: 20px;
            text-align: center;
            font-weight: bold;
        }
    </style>
</head>
<body>

<h1>JavaScript Topics with Navigation</h1>

<!-- Navigation Menu -->
<nav>
    <h2>📚 Topics Index</h2>
    <a href="#variables">1. Variables</a>
    <a href="#data-types">2. Data Types</a>
    <a href="#operators">3. Operators</a>
    <a href="#control-flow">4. Control Flow</a>
    <a href="#loops">5. Loops</a>
    <a href="#functions">6. Functions</a>
    <a href="#arrays">7. Arrays</a>
    <a href="#objects">8. Objects</a>
    <a href="#events">9. Events</a>
    <a href="#dom">10. DOM Manipulation</a>
    <a href="#error-handling">11. Error Handling</a>
    <a href="#es6">12. ES6 Features</a>
    <a href="#promises">13. Promises</a>
</nav>

<!-- Topics Section -->

<section id="variables">
    <h2>1. Variables</h2>
    <p><strong>Definition:</strong> Variables store data that can be used later in your program.</p>
    <pre><code>
// Syntax:
let name = "Alice";
const age = 25;
var city = "Paris";

// Example:
let x = 10;
x = 20;
console.log(x);   // Output: 20
    </code></pre>
    <a href="#top" class="back-to-top">⬆️ Back to Top</a>
</section>

<section id="data-types">
    <h2>2. Data Types</h2>
    <p><strong>Definition:</strong> JavaScript supports multiple data types, including string, number, and boolean.</p>
    <pre><code>
// Syntax:
let str = "Hello";
let num = 123;
let bool = true;

// Example:
console.log(typeof str);   // Output: string
console.log(typeof num);   // Output: number
    </code></pre>
    <a href="#top" class="back-to-top">⬆️ Back to Top</a>
</section>

<section id="operators">
    <h2>3. Operators</h2>
    <p><strong>Definition:</strong> Operators perform operations on variables and values.</p>
    <pre><code>
// Syntax:
let sum = 5 + 2;
let diff = 10 - 3;

// Example:
let a = 10, b = 5;
console.log(a + b);    // Output: 15
console.log(a > b);    // Output: true
    </code></pre>
    <a href="#top" class="back-to-top">⬆️ Back to Top</a>
</section>

<section id="control-flow">
    <h2>4. Control Flow (If-Else)</h2>
    <p><strong>Definition:</strong> Used for executing code based on conditions.</p>
    <pre><code>
// Syntax:
if (condition) {
    // Code if true
} else {
    // Code if false
}

// Example:
let age = 18;
if (age >= 18) {
    console.log("Adult");
} else {
    console.log("Minor");
}
    </code></pre>
    <a href="#top" class="back-to-top">⬆️ Back to Top</a>
</section>

<section id="loops">
    <h2>5. Loops</h2>
    <p><strong>Definition:</strong> Loops are used to repeat a block of code multiple times.</p>
    <pre><code>
// Syntax:
for (let i = 0; i < 5; i++) {
    console.log(i);
}

// Example:
let j = 0;
while (j < 5) {
    console.log(j);
    j++;
}
    </code></pre>
    <a href="#top" class="back-to-top">⬆️ Back to Top</a>
</section>

<section id="functions">
    <h2>6. Functions</h2>
    <p><strong>Definition:</strong> Functions are reusable blocks of code.</p>
    <pre><code>
// Syntax:
function greet(name) {
    console.log("Hello " + name);
}

// Example:
greet("Alice");   // Output: Hello Alice
    </code></pre>
    <a href="#top" class="back-to-top">⬆️ Back to Top</a>
</section>

<section id="arrays">
    <h2>7. Arrays</h2>
    <p><strong>Definition:</strong> Arrays store multiple values in a single variable.</p>
    <pre><code>
// Syntax:
let colors = ["Red", "Green", "Blue"];

// Example:
console.log(colors[0]);   // Output: Red
    </code></pre>
    <a href="#top" class="back-to-top">⬆️ Back to Top</a>
</section>

<section id="objects">
    <h2>8. Objects</h2>
    <p><strong>Definition:</strong> Objects store data in key-value pairs.</p>
    <pre><code>
// Syntax:
let person = {
    name: "Alice",
    age: 25
};

// Example:
console.log(person.name);   // Output: Alice
    </code></pre>
    <a href="#top" class="back-to-top">⬆️ Back to Top</a>
</section>

<section id="events">
    <h2>9. Events</h2>
    <p><strong>Definition:</strong> Events respond to user interactions.</p>
    <pre><code>
// Syntax:
<button onclick="alert('Button clicked!')">Click Me</button>
    </code></pre>
    <a href="#top" class="back-to-top">⬆️ Back to Top</a>
</section>

<section id="dom">
    <h2>10. DOM Manipulation</h2>
    <p><strong>Definition:</strong> DOM allows JavaScript to manipulate HTML elements.</p>
    <pre><code>
// Syntax:
document.getElementById("demo").innerHTML = "Hello, DOM!";
    </code></pre>
    <a href="#top" class="back-to-top">⬆️ Back to Top</a>
</section>

<section id="error-handling">
    <h2>11. Error Handling</h2>
    <p><strong>Definition:</strong> Manages runtime errors.</p>
    <pre><code>
try {
    let x = y;    
} catch (error) {
    console.log("Error occurred: " + error);
}
    </code></pre>
    <a href="#top" class="back-to-top">⬆️ Back to Top</a>
</section>

<section id="es6">
    <h2>12. ES6 Features</h2>
    <p><strong>Definition:</strong> New JS features like arrow functions.</p>
    <pre><code>
const greet = (name) => `Hello, ${name}`;
console.log(greet("Alice"));
    </code></pre>
    <a href="#top" class="back-to-top">⬆️ Back to Top</a>
</section>

<section id="promises">
    <h2>13. Promises</h2>
    <pre><code>
let promise = new Promise((resolve, reject) => {
    resolve("Done");
});
    </code></pre>
    <a href="#top" class="back-to-top">⬆️ Back to Top</a>
</section>

</body>
</html>