| class Person { |
| constructor(name, age) { |
| this.name = name; |
| this.age = age; |
| } |
| greet() { |
| console.log(' ${this.name} ${this.age}.'); |
| } |
| } |
| let person = new Person("", 30); |
| if (person.age >= 18) { |
| console.log(""); |
| } else { |
| console.log(""); |
| } |
| for (let i = 0; i < 5; i++) { |
| console.log(i); |
| } |
| let fruits = ["", "", ""]; |
| fruits.push(""); |
| console.log(fruits); |
| function add(a, b) { |
| return a + b; |
| } |
| console.log(add(2, 3)); |
| async function fetchData() { |
| let response = await fetch('https://'); |
| let data = await response.json(); |
| console.log(data); |
| } |
| fetchData(); |
| try { |
| let result = someFunctionThatMightThrowError(); |
| } catch (error) { |
| console.error(error); |
| } |
| const PI = 3.14; |
| let radius = 5; |
| let area = PI * radius * radius; |
| console.log(area); |
| let date = new Date(); |
| console.log(date); |
| let str = ""; |
| console.log(str.substring(0, 5)); |
| console.log(str.replace("", "")); |
| console.log(Math.random()); |
| console.log(Math.max(1, 2, 3)); |
| let obj = { name: "", age: 30 }; |
| let jsonStr = JSON.stringify(obj); |
| console.log(jsonStr); |
| window.alert("!"); |
| document.getElementById("myDiv").innerHTML = "!"; |
Комментарии