ChatGPT said:
Here are 100 clean, practical lines on JavaScript for your study notes, revision, or teaching slides:
JavaScript is a high-level, interpreted programming language.
It was created by Brendan Eich in 1995.
JavaScript is lightweight and dynamic.
It is a core technology of the web, alongside HTML and CSS.
JavaScript is used to create interactive web pages.
It can be used for client-side and server-side development.
JavaScript is case-sensitive.
Statements end with a semicolon (optional but recommended).
JavaScript code can be included in HTML using <script> tags.
It can also be used in external .js files.
JavaScript supports primitive data types: string, number, boolean, null, undefined, symbol, bigint.
It also supports objects and arrays as reference types.
Variables can be declared using var, let, and const.
var is function-scoped; let and const are block-scoped.
const declares constants that cannot be reassigned.
JavaScript supports functions, which can be declared or assigned to variables.
Functions can be arrow functions: const add = (a, b) => a + b;
JavaScript supports object-oriented programming using prototypes and classes.
Classes were introduced in ES6 (2015).
JavaScript supports inheritance using prototypes.
JavaScript uses dynamic typing (no explicit type declarations).
Arrays can be declared as let arr = [1, 2, 3];.
Objects can be declared as let obj = { key: "value" };.
Strings can be enclosed in single, double, or backticks.
Backticks allow template literals: `Hello, ${name}`.
JavaScript uses === for strict equality, checking value and type.
== performs type coercion during comparison.
Conditional statements use if, else if, else.
Loops include for, while, do...while, and for...of.
for...in loops over object properties.
Functions can have default parameters: function greet(name = "Guest").
Functions can return values using return.
JavaScript has built-in methods like console.log().
Browser’s console helps in debugging JavaScript code.
JavaScript can manipulate the DOM (Document Object Model).
document.getElementById("id") selects an element by ID.
document.querySelector(".class") selects the first matching element.
document.querySelectorAll(".class") selects all matching elements.
Events can be handled using .addEventListener().
Example: button.addEventListener("click", function() { });
JavaScript can modify CSS using .style property.
JavaScript supports event bubbling and capturing.
Functions can be anonymous.
Functions can be immediately invoked: (function() { })();.
JavaScript has built-in objects like Math, Date, JSON.
Math.random() generates a random number between 0 and 1.
Date can get the current date and time: new Date().
JSON is used for data exchange in JavaScript.
JSON.stringify() converts objects to JSON strings.
JSON.parse() parses JSON strings to objects.
JavaScript supports error handling using try...catch.
Example:
js
CopyEdit
try {
riskyFunction();
} catch (error) {
console.log(error);
}
JavaScript supports asynchronous programming.
Asynchronous operations can use callbacks.
Promises are used for better asynchronous flow.
Example Promise:
js
CopyEdit
let promise = new Promise((resolve, reject) => { resolve("done"); });
Promises use .then() for resolved results and .catch() for errors.
JavaScript supports async and await for clean async code.
Example:
js
CopyEdit
async function fetchData() { let data = await getData(); }
JavaScript can fetch APIs using fetch().
Example:
js
CopyEdit
fetch(url).then(res => res.json()).then(data => console.log(data));
JavaScript runs in browsers and Node.js environments.
Node.js allows JavaScript to run on servers.
JavaScript supports modules using export and import.
Example: export function greet() { } in one file.
Example: import { greet } from './file.js' in another file.
Arrays have useful methods: .push(), .pop(), .shift(), .unshift().
.map() applies a function to each array element and returns a new array.
.filter() returns a new array with elements that match a condition.
.reduce() applies a function to accumulate array values.
.forEach() executes a function for each array element.
Objects can be accessed using dot notation: obj.key.
Objects can also be accessed using bracket notation: obj["key"].
You can loop over arrays using for...of.
Example:
js
CopyEdit
for (let item of arr) { console.log(item); }
You can loop over object keys using for...in.
JavaScript has a typeof operator to check data types.
Example: typeof "Hello" returns "string".
JavaScript uses lexical scoping.
Functions have closures, remembering the scope in which they were created.
JavaScript uses hoisting for variable and function declarations.
Variables declared with var are hoisted and initialized with undefined.
let and const declarations are hoisted but not initialized.
Functions declared with function are hoisted entirely.
JavaScript uses the event loop for handling asynchronous operations.
The call stack handles synchronous code.
The task queue handles callbacks and async operations.
JavaScript supports regular expressions using /pattern/.
Example: /\d+/ matches one or more digits.
JavaScript can manipulate strings using methods like .toUpperCase(), .toLowerCase(), .trim().
Strings are immutable in JavaScript.
JavaScript can create and manipulate dates with Date methods like .getFullYear(), .getMonth().
JavaScript has utility libraries like Lodash and Moment.js for advanced operations.
JavaScript engines like V8 (Chrome) and SpiderMonkey (Firefox) execute JS code.
Modern JavaScript uses ES6 features like arrow functions, classes, and destructuring.
Destructuring allows unpacking values:
js
CopyEdit
let [a, b] = [1, 2];
let { x, y } = { x: 10, y: 20 };
JavaScript can interact with Web APIs like Geolocation, LocalStorage, and Canvas.
LocalStorage can store key-value pairs in the browser: localStorage.setItem("key", "value").
JavaScript is essential for modern frameworks like React, Angular, and Vue.
JavaScript is continuously evolving, making it one of the most powerful and in-demand languages in the world.
If you need next:
✅ A JavaScript syntax cheat sheet
✅ 10 beginner JavaScript mini projects
✅ 50 JavaScript interview questions
✅ A JavaScript practice test for mastery
Here are 100 practical JavaScript “cheat code” lines for daily coding, testing, and memory building:
console.log("Hello World"); // print to console
let x = 5; // declare variable
const y = 10; // constant value
var z = 15; // old-style variable
x += 2; // increment by 2
x++; // increment by 1
x--; // decrement by 1
console.log(typeof x); // check type
let str = "JavaScript"; // string value
let bool = true; // boolean value
let arr = [1, 2, 3]; // array
let obj = {name: "Alice", age: 25}; // object
arr.push(4); // add to end
arr.pop(); // remove from end
arr.shift(); // remove from start
arr.unshift(0); // add to start
arr.length; // array length
arr.includes(2); // check if array includes
let sum = arr.reduce((a, b) => a + b); // sum array
arr.map(x => x * 2); // double array values
arr.filter(x => x > 1); // filter values > 1
arr.find(x => x === 2); // find specific value
arr.indexOf(2); // find index of 2
for (let i = 0; i < arr.length; i++) { console.log(arr[i]); } // loop
for (let item of arr) { console.log(item); } // for..of
for (let key in obj) { console.log(key); } // for..in
if (x > 5) { console.log("Greater"); } // if statement
else { console.log("Not greater"); } // else
x === 5 ? "Yes" : "No"; // ternary
function greet(name) { return "Hello " + name; } // function
const greet = name => "Hello " + name; // arrow function
(function() { console.log("IIFE"); })(); // IIFE
const [a, b] = [1, 2]; // array destructuring
const {name, age} = obj; // object destructuring
let str2 = \Hello ${name}`;` // template literal
"abc".toUpperCase(); // uppercase
"ABC".toLowerCase(); // lowercase
" trim ".trim(); // trim spaces
"JavaScript".includes("Script"); // check substring
"Hello".split(""); // split into array
[..."Hello"]; // spread string to array
let merged = [...arr, 4, 5]; // merge arrays
let copy = {...obj}; // shallow copy object
JSON.stringify(obj); // object to JSON
JSON.parse('{"name":"Alice"}'); // JSON to object
new Date(); // current date
Date.now(); // current timestamp
Math.random(); // random number 0-1
Math.floor(Math.random() * 10); // random 0-9
Math.max(1, 2, 3); // max value
Math.min(1, 2, 3); // min value
Math.round(4.5); // round number
isNaN("abc"); // check NaN
Number("123"); // convert to number
String(123); // convert to string
Boolean(0); // convert to boolean
parseInt("10", 10); // parse integer
parseFloat("10.5"); // parse float
typeof 42; // returns "number"
typeof "abc"; // returns "string"
typeof true; // returns "boolean"
typeof {}; // returns "object"
typeof []; // returns "object" (arrays are objects)
typeof null; // returns "object" (quirk)
typeof undefined; // returns "undefined"
null === undefined; // false
null == undefined; // true
console.error("Error message"); // error log
console.warn("Warning message"); // warning log
console.table(arr); // display array as table
alert("Hello!"); // alert popup
prompt("Enter your name"); // input popup
confirm("Are you sure?"); // confirm popup
setTimeout(() => console.log("Delayed"), 1000); // delay 1s
setInterval(() => console.log("Repeating"), 1000); // repeat every 1s
clearTimeout(timerId); // clear timeout
clearInterval(intervalId); // clear interval
try { JSON.parse("{"); } catch (e) { console.error(e); } // try-catch
document.getElementById("id"); // get by ID
document.querySelector(".class"); // get by selector
document.querySelectorAll("div"); // get all elements
element.textContent = "Text"; // set text
element.innerHTML = "<b>Bold</b>"; // set HTML
element.style.color = "red"; // change style
element.addEventListener("click", () => alert("Clicked")); // event listener
window.localStorage.setItem("key", "value"); // set localStorage
window.localStorage.getItem("key"); // get localStorage
window.localStorage.removeItem("key"); // remove localStorage
window.localStorage.clear(); // clear all localStorage
navigator.geolocation.getCurrentPosition(pos => console.log(pos)); // get location
fetch("https://api.example.com") // fetch API
.then(response => response.json()) // parse JSON
.then(data => console.log(data)) // handle data
.catch(error => console.error(error)); // catch error
class Person { constructor(name) { this.name = name; } } // class
let p = new Person("Alice"); // instantiate class
p instanceof Person; // true
Array.isArray(arr); // check if array
new Promise((resolve, reject) => resolve("Done")); // promise
async function getData() { let data = await fetch(url); } // async/await