knowledge

Overview

JavaScript (JS) is a scripting language used to add interactivity and dynamic behavior to websites. It runs directly in the browser as an interpreted client-side language and works alongside HTML and CSS to enable dynamic content, user interaction, and client-side logic.


Terminology

TermDefinition
VariableNamed storage location holding a value
FunctionReusable block of code designed to perform a specific task
LoopConstruct that repeatedly executes code while a condition is true
Control FlowDetermines the order of code execution based on conditions
MinificationRemoves whitespace and comments to reduce file size
ObfuscationMakes code harder to read by renaming variables and adding dummy logic
DeobfuscationReversing obfuscation to analyze and understand code
DOMDocument Object Model; browser’s structured representation of an HTML page

Core Concepts

Variables

Used to store data values for use throughout a script.

DeclarationScopeNotes
varFunction-scopedLegacy; avoid in modern JS
letBlock-scopedPreferred for mutable values
constBlock-scopedCannot be reassigned after declaration

Data Types

string, number, boolean, null, undefined, object

Functions

  • Block of code designed to perform a specific task
  • Can be reused throughout a program
  • Defined with function name() {} or as arrow functions () => {}

Loops

Execute code repeatedly while a condition is true.

LoopUse Case
forKnown number of iterations
whileUnknown number of iterations; checks condition first
do...whileExecutes at least once before checking condition

Control Flow

StructureDescription
if-elseExecutes different code based on a condition
switchMulti-branch decision structure for discrete values

Integrating JavaScript into HTML

Internal JavaScript

Embedded directly in HTML using <script> tags.

  • In <head> — loads before page content
  • In <body> — interacts with already-loaded elements

External JavaScript

Stored in .js files and linked via <script src="file.js"> — improves organization and reusability.

Quick identification:

  • <script src="..."> → External JS file
  • <script> ... </script> → Inline/Internal JS

Dialogue Functions

Built-in browser functions for user interaction.

FunctionDescription
alert()Displays a message to the user
prompt()Requests text input from the user
confirm()Returns true or false based on user choice
⚠︎Security Note

These functions can be abused in XSS attacks — see XSS

Minification & Obfuscation

TechniquePurpose
MinificationReduces file size by removing spaces, comments, and newlines
ObfuscationMakes code harder to reverse-engineer; common in malware
DeobfuscationReversing obfuscation to analyze code during security testing


References / Images

  • JavaScript function diagrams
  • Loop and control flow visualizations
  • Internal vs external JS integration examples