Codekilla Programming Lab.
Master programming fundamentals through guided walk-throughs, workflow diagrams, and runnable code examples. Every concept you need before your first real project.
Introduction to Programming
Understanding the fundamentals of how computers execute instructions
Programming is the process of creating instructions that a computer can execute to perform specific tasks. It's like writing a recipe, but for computers. Programs flow through four stages: writing code, translating that code to machine form (compilation or interpretation), executing it on the CPU, and producing output — whether that's a value on screen, a file on disk, or a network response.
- Write Code — developer creates source code in a programming language
- Compilation / Interpretation — code is translated to machine-readable format
- Execution — CPU processes the instructions
- Output — program produces results (screen, file, network…)
// Hello, World! in JavaScript
console.log('Hello, World!');Variables
Containers for storing data values that change during execution
A variable is like a labelled box that holds a value. You can store data, read it, and change it later. Lifecycle: declaration (reserve memory) → initialisation (first value) → usage → modification.
- let name; // Declaration
- name = 'Ashok'; // Initialisation
- console.log(name); // Usage
- name = 'Codekilla'; // Modification
let message = 'Hi!';
let count = 0;
count = count + 1;
console.log(message, count); // Hi! 1Constants
Immutable values that can't be changed after initialisation
A constant is a name bound to a value that cannot be reassigned. Use `const` when the reference is fixed — like mathematical values, config keys, or lookup tables.
| Feature | Variable (let) | Constant (const) |
|---|---|---|
| Can be reassigned? | Yes | No |
| Must initialise? | Optional | Required |
| Use case | Values that change | Values that stay fixed |
const PI = 3.14159;
const TAX_RATE = 0.18;
// PI = 3; // TypeError: Assignment to constantData Types
Different kinds of data that can be stored and manipulated
Programming languages work with a small set of primitive data types that combine to form rich data structures. Knowing when to reach for each keeps your code correct and efficient.
let age = 24; // number
let name = 'Ada'; // string
let active = true; // boolean
let data = null; // nullOperators
Symbols that perform operations on values and variables
Operators are the verbs of a language — they do things.
| Type | Operators | Example | Result |
|---|---|---|---|
| Arithmetic | + - * / % | 10 + 5 | 15 |
| Comparison | == != < > <= >= | 10 > 5 | true |
| Logical | && || ! | true && false | false |
| Assignment | = += -= *= /= | x += 5 | x = x + 5 |
const a = 7, b = 2;
console.log(a + b); // 9
console.log(a / b); // 3.5
console.log(a > b); // trueIf Statements
Making decisions in code based on conditions
Conditionals branch the execution path based on boolean expressions. Use else if for ladders and default to the general case.
- Evaluate boolean expression
- If true → run the `if` block
- If false → run the `else` block (or nothing)
- Continue with next statement
const age = 20;
if (age >= 18) {
console.log('Eligible to vote');
} else {
console.log('Come back at 18');
}Loops
Repeating code execution multiple times
Loops save you from copy-pasting. Three flavours in most languages: for (fixed count), while (condition-first), do-while (condition-after).
for (let i = 0; i < 5; i++) console.log(i);
let n = 3;
while (n > 0) { console.log(n); n--; }Arrays
Ordered collections of elements under one variable
Arrays are zero-indexed lists. Use them to model sequences: students in a class, tasks in a queue, frames of an animation.
| Operation | Method | Description |
|---|---|---|
| Add to end | push() | Appends to the array |
| Remove from end | pop() | Removes and returns last |
| Add to start | unshift() | Prepends |
| Remove from start | shift() | Removes and returns first |
| Length | .length | Number of elements |
const fruits = ['apple', 'banana', 'orange'];
fruits.push('mango');
for (const f of fruits) console.log(f);Strings
Sequences of characters used to represent text
Strings are immutable in most languages. Use template literals for interpolation, and built-in methods for trimming, splitting, replacing, and searching.
const name = 'Codekilla';
console.log(`Hello, ${name}!`);
console.log(name.toUpperCase()); // CODEKILLAFunctions
Reusable blocks of code that perform specific tasks
A function encapsulates logic. Call it by name, pass arguments, get a return value. Small, focused functions (under 30 lines) are the hallmark of maintainable code.
- Function Call — invoke with arguments
- Parameter Binding — arguments map to parameters
- Execute Body — run function code
- Return Value — send result back
function add(a, b) {
return a + b;
}
const arrow = (x) => x * x;
console.log(add(3, 4), arrow(5)); // 7 25Recursion
Functions that call themselves to solve problems
A recursive function solves a big problem by solving smaller versions of the same problem. Always include a base case — otherwise you stack-overflow.
function factorial(n) {
if (n <= 1) return 1; // base case
return n * factorial(n - 1);
}
console.log(factorial(5)); // 120Scope
The accessibility and visibility of variables
Global scope is accessible everywhere. Function scope is local to a function. Block scope ({ }) applies to let/const inside braces.
const global_x = 1;
function f() {
const local_y = 2;
if (true) {
const block_z = 3;
console.log(global_x, local_y, block_z);
}
// block_z is not accessible here
}Type Casting
Converting values from one data type to another
Implicit coercion happens automatically (e.g. '5' + 1 → '51'). Explicit casting is safer — you declare intent.
console.log(Number('42') + 1); // 43
console.log(String(42) + 1); // '421'
console.log(Boolean('')); // falseBits & Bytes
The fundamental units of digital information
A bit is a single 0 or 1. Eight bits make a byte. Memory and storage are measured in bytes and their multiples.
| Unit | Size | Example |
|---|---|---|
| Bit | 1 bit | 0 or 1 |
| Nibble | 4 bits | 1011 |
| Byte | 8 bits | 10110101 |
| Kilobyte (KB) | 1024 bytes | Small text file |
| Megabyte (MB) | 1024 KB | High-res image |
| Gigabyte (GB) | 1024 MB | HD movie |
const byte = 0b10110101; // 181
console.log(byte.toString(2)); // '10110101'Number Systems
Binary, Octal, Decimal, Hexadecimal
A number system is a way of representing numbers using a set of symbols. The base (radix) determines how many unique digits are available.
| Decimal | Binary | Octal | Hex |
|---|---|---|---|
| 0 | 0000 | 0 | 0 |
| 5 | 0101 | 5 | 5 |
| 10 | 1010 | 12 | A |
| 15 | 1111 | 17 | F |
| 16 | 10000 | 20 | 10 |
| 255 | 11111111 | 377 | FF |
// Different base literals in JS
const bin = 0b1010; // 10
const oct = 0o12; // 10
const hex = 0xA; // 10
console.log(bin, oct, hex); // 10 10 10Boolean Algebra
Logic operations with true / false values
Three fundamental operators — AND, OR, NOT — let you combine booleans. They're the foundation of every conditional you'll ever write.
| A | B | A && B | A || B |
|---|---|---|---|
| false | false | false | false |
| false | true | false | true |
| true | false | false | true |
| true | true | true | true |
console.log(true && false); // false
console.log(true || false); // true
console.log(!true); // falseInput & Output
Getting data from users and displaying results
Every program follows Input → Process → Output. Input can come from keyboards, files, APIs. Output goes to the console, DOM, files, or network responses.
- Input — receive data (keyboard, mouse, file, network)
- Validation — check the input is safe & valid
- Processing — transform the data
- Output — deliver the result to the right destination
const name = prompt('Your name?');
const upper = (name || 'friend').toUpperCase();
console.log(`Hello, ${upper}!`);
Comments
Documentation inside code that's ignored by the compiler
Comments explain intent. They help future-you, your teammates, and reviewers understand *why* the code does what it does — not *what* it does (the code itself already says that).