- 01 Intro to JavaScript
- Basic syntax
- [[#Basic syntax#1. Hello World! Printing to the console|1. Hello World! Printing to the console]]
- [[#Basic syntax#2. Alert and window prompts|2. Alert and window prompts]]
- [[#Basic syntax#3. Take user input through html textbox|3. Take user input through html textbox]]
- [[#Basic syntax#logging|logging]]
01 Intro to JavaScript
- JavaScript is a programming and scripting language used for frontend as well as backend web development
- We use JS along with HTML and CSS to design and make responsive web pages
- JS is an mainly an interpreted language and also a compiled language.
- Interpreted:
- Traditionally, JavaScript was interpreted line-by-line by the browser’s JavaScript engine (V8).
- The engine reads the source code, parses it, and executes it directly without prior conversion to machine code.
- This interpretation process is relatively straightforward and allows for quick startup times.
-
- Compiled:
1. modern JavaScript engines often use a combination of interpretation and compilation techniques to improve performance.
- They may initially parse the JavaScript code and then compile it into an intermediate representation.
- This representation can be optimized and further compiled (“Just-In-Time” compilation) into machine code for execution.
- compilation allows for performance improvements for frequently executed code paths.
Basic syntax
1. Hello World! Printing to the console
// this is our hello world code
console.log("Hello World!");
console.error("there was an error fetching data!");
grouped Logs
console.group("Alphabets");
console.log("A");
console.log("B");
console.log("C");
console.groupEnd()
console.groupCollapsed("Alphabets");
console.log("A");
console.log("A");
console.groupEnd()
2. Alert and window prompts
alert("hello world");
alert("X-men '97 is awesome!");
let name = window.prompt(`enter your name:`);
3. Take user input through html textbox
<input placeholder="username" id="box1" type="text"></input>
let name = document.getElementById("username").value;
logging
console.log("");
console.info("");
console.warn("");
console.error("");
alert("Hello");
let name = prompt("Enter name:");
let response = confirm("Sure?");
// returns boolean