|
| 1 | +# **Deno Online Compiler** |
| 2 | + |
| 3 | +Write, Run & Share Deno code online using OneCompiler's Deno online compiler for free. It's a modern, secure, and feature-rich runtime for JavaScript and TypeScript. Getting started with OneCompiler's Deno editor is easy and fast. The editor shows sample boilerplate code when you choose Deno as the language and start coding. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +# **About Deno** |
| 8 | + |
| 9 | +**Deno** is a secure runtime for JavaScript and TypeScript, built on V8 and Rust. It is designed by the creator of Node.js to improve upon its shortcomings, offering modern features with better security and developer experience. |
| 10 | + |
| 11 | +--- |
| 12 | + |
| 13 | +# **Key Features** |
| 14 | + |
| 15 | +- **Secure by default**: No file, network, or environment access unless explicitly granted. |
| 16 | +- **Built-in TypeScript support**: No need for a separate compiler. |
| 17 | +- **Uses modern ES modules**: No need for `package.json` or `node_modules`. |
| 18 | +- **Ships with a built-in formatter, linter, and test runner**. |
| 19 | +- **Supports Web APIs**: Similar to browsers, Deno includes APIs like `fetch()`. |
| 20 | + |
| 21 | +--- |
| 22 | + |
| 23 | +# **Syntax Help** |
| 24 | + |
| 25 | +## **Hello World** |
| 26 | +```typescript |
| 27 | +console.log("Hello, World!"); |
| 28 | +``` |
| 29 | + |
| 30 | +## **Variable Declaration** |
| 31 | + |
| 32 | +| Keyword | Description | Scope | |
| 33 | +|----------|---------------------------------|----------------------| |
| 34 | +| `var` | Old way of declaring variables | Function or global | |
| 35 | +| `let` | Block-scoped variable | Block scope | |
| 36 | +| `const` | Constant, cannot be reassigned | Block scope | |
| 37 | + |
| 38 | +--- |
| 39 | + |
| 40 | +## **Arrow Functions** |
| 41 | +Arrow functions provide a more concise syntax for defining functions. |
| 42 | + |
| 43 | +### **Syntax:** |
| 44 | +```typescript |
| 45 | +const greet = (name: string): string => `Hello, ${name}!`; |
| 46 | +console.log(greet("Deno")); |
| 47 | +``` |
| 48 | + |
| 49 | +--- |
| 50 | + |
| 51 | +## **Template Literals (Backtick Strings)** |
| 52 | + |
| 53 | +### **Interpolation** |
| 54 | +```typescript |
| 55 | +let name = "Deno"; |
| 56 | +console.log(`Hello, ${name}!`); |
| 57 | +``` |
| 58 | + |
| 59 | +### **Multi-line Strings** |
| 60 | +```typescript |
| 61 | +const message = ` |
| 62 | +Hello, |
| 63 | +Welcome to Deno! |
| 64 | +`; |
| 65 | +console.log(message); |
| 66 | +``` |
| 67 | + |
| 68 | +--- |
| 69 | + |
| 70 | +## **Arrays** |
| 71 | + |
| 72 | +An array is a collection of values. |
| 73 | + |
| 74 | +### **Syntax:** |
| 75 | +```typescript |
| 76 | +let numbers: number[] = [1, 2, 3, 4, 5]; |
| 77 | +console.log(numbers[0]); // Accessing first element |
| 78 | +``` |
| 79 | + |
| 80 | +### **Spread operator with Arrays** |
| 81 | +```typescript |
| 82 | +let moreNumbers = [...numbers, 6, 7, 8]; |
| 83 | +console.log(moreNumbers); |
| 84 | +``` |
| 85 | + |
| 86 | +--- |
| 87 | + |
| 88 | +## **Object Destructuring** |
| 89 | + |
| 90 | +### **Example:** |
| 91 | +```typescript |
| 92 | +const user = { name: "Alice", age: 25 }; |
| 93 | +const { name, age } = user; |
| 94 | +console.log(name, age); |
| 95 | +``` |
| 96 | + |
| 97 | +--- |
| 98 | + |
| 99 | +## **Loops** |
| 100 | + |
| 101 | +### **For Loop** |
| 102 | +```typescript |
| 103 | +for (let i = 0; i < 5; i++) { |
| 104 | + console.log(i); |
| 105 | +} |
| 106 | +``` |
| 107 | + |
| 108 | +### **While Loop** |
| 109 | +```typescript |
| 110 | +let count = 0; |
| 111 | +while (count < 5) { |
| 112 | + console.log(count); |
| 113 | + count++; |
| 114 | +} |
| 115 | +``` |
| 116 | + |
| 117 | +### **Do-While Loop** |
| 118 | +```typescript |
| 119 | +let num = 0; |
| 120 | +do { |
| 121 | + console.log(num); |
| 122 | + num++; |
| 123 | +} while (num < 5); |
| 124 | +``` |
| 125 | + |
| 126 | +--- |
| 127 | + |
| 128 | +## **Classes** |
| 129 | + |
| 130 | +Deno supports ES6 classes, allowing for object-oriented programming. |
| 131 | + |
| 132 | +### **Example:** |
| 133 | +```typescript |
| 134 | +class Car { |
| 135 | + model: string; |
| 136 | + constructor(model: string) { |
| 137 | + this.model = model; |
| 138 | + } |
| 139 | + showModel() { |
| 140 | + console.log(`Car model: ${this.model}`); |
| 141 | + } |
| 142 | +} |
| 143 | + |
| 144 | +const myCar = new Car("Tesla Model S"); |
| 145 | +myCar.showModel(); |
| 146 | +``` |
| 147 | + |
| 148 | +--- |
| 149 | + |
| 150 | +Deno is a modern and secure alternative to Node.js, offering built-in TypeScript support and a more streamlined developer experience. With its security-first approach and native ES module support, it is a great choice for modern JavaScript and TypeScript applications. |
| 151 | + |
0 commit comments