×
Javascript Tutorial
JS Functions
Common functions
1. String Functions
| Function | Purpose | Example |
|---|
| toUpperCase() | Convert text to uppercase | "hello".toUpperCase() |
|---|
| toLowerCase() | Convert text to lowercase | "HELLO".toLowerCase() |
|---|
| trim() | Remove extra spaces | " hi ".trim() |
|---|
| length | Get string length | "hello".length |
|---|
| replace() | Replace text | "a".replace("a","b") |
|---|
2. Array Functions
| Function | Purpose | Example |
|---|
| push() | Add element at end | arr.push(10) |
|---|
| pop() | Remove last element | arr.pop() |
|---|
| shift() | Remove first element | arr.shift() |
|---|
| unshift() | Add element at start | arr.unshift(1) |
|---|
| map() | Modify array elements | arr.map(x => x*2) |
|---|
| filter() | Filter elements | arr.filter(x => x > 10) |
|---|
| forEach() | Loop through array | arr.forEach() |
|---|
3. Number Functions
| Function | Purpose | Example |
|---|
| parseInt() | Convert to integer | parseInt("10") |
|---|
| parseFloat() | Convert to decimal | parseFloat("10.5") |
|---|
| Number() | Convert to number | Number("25") |
|---|
| isNaN() | Check Not a Number | isNaN("abc") |
|---|
4. JSON Functions
5. Common Browser Functions
| Function | Purpose | Example |
|---|
| alert() | Popup message | alert("Hello") |
|---|
| prompt() | User input | prompt("Enter name") |
|---|
| confirm() | OK/Cancel dialog | confirm("Sure?") |
|---|
| console.log() | Debug output | console.log("Hi") |
|---|
| document.write() | Write on page | document.write("Hello") |
|---|
6. Timer Functions
| Function | Purpose | Example |
|---|
| setTimeout() | Run after delay | setTimeout(fn,1000) |
|---|
| setInterval() | Run repeatedly | setInterval(fn,1000) |
|---|
| clearTimeout() | Stop timeout | clearTimeout(id) |
|---|
| clearInterval() | Stop interval | clearInterval(id) |
|---|