Article image Introduction to HTML: basic structure, tags and attributes: JavaScript Operators

4.25. Introduction to HTML: basic structure, tags and attributes: JavaScript Operators

Page 29 | Listen in audio

4.25. Introduction to HTML: basic structure, tags and attributes: JavaScript Operators

The HTML (HyperText Markup Language) markup language is the backbone of any website or web application. It provides the basic structure, which is then enhanced and modified by CSS and JavaScript. Understanding HTML is crucial for any front-end developer. In this chapter, we'll explore the basic structure of HTML, its tags and attributes, and also dive into JavaScript operators.

Basic Structure of HTML

An HTML document is structured like a tree, with an 'html' element at the top. This element contains two child elements: 'head' and 'body'. The 'head' element contains metadata about the document, including the title that appears in the browser tab and links to CSS files. The 'body' element contains the main content of the website, including text, images, videos and links.

<html>
  <head>
    <title>Site Title</title>
  </head>
  <body>
    Site content goes here.
  </body>
</html>

HTML Tags and Attributes

HTML tags are used to define elements and content of a website. Each tag begins with a angle bracket (<) and ends with an angle bracket (>). Tags usually come in pairs, with an opening tag and a closing tag. The closing tag is identical to the opening tag, but has a slash (/) before the tag name.

HTML attributes are used to provide additional information about an element. They are always specified in the opening tag and usually come in name-value pairs. For example, the 'img' tag uses the 'src' attribute to specify the URL of the image and the 'alt' attribute to provide alternative text for the image.

<img src="url_da_imagem.jpg" alt="Image description">

JavaScript Operators

JavaScript is a programming language that allows you to add interactivity and complex functionality to a website. Operators are symbols that specify which operation to perform. There are several types of operators in JavaScript, including arithmetic, assignment, comparison, logical, and type operators.

Arithmetic operators are used to perform mathematical operations. For example, '+' is used for addition, '-' for subtraction, '*' for multiplication, '/' for division, and '%' to get the remainder of a division.

let x = 10;
let y = 5;

console.log(x + y); // 15
console.log(x - y); // 5
console.log(x * y); // 50
console.log(x / y); // two
console.log(x % y); // 0

Assignment operators are used to assign values ​​to variables. The '=' operator is the most common, but there are many others, including '+=' and '-=', which add or subtract a value from a variable and then assign the result to the variable.

let x = 10;

x += 5; // x is now 15
x -= 3; // x is now 12

Comparison operators are used to compare two values. They return a boolean value: true if the comparison is true, false if it is false. Some examples include '==' (equal to), '!=' (not equal to), '<' (less than), '>' (greater than), '<=' (less than or equal to) and '>=' (greater than or equal to).

let x = 10;
let y = 5;

console.log(x == y); // false
console.log(x != y); // true
console.log(x < y); // false
console.log(x > y); // true
console.log(x <= y); // false
console.log(x >= y); // true

Logical operators are used to test various conditions. They include '&&' (and), '||' (or) and '!' (no).

let x = 10;
let y = 5;
let z = 20;

console.log(x > y && x < z); // true
console.log(x > y || x > z); // true
console.log(!(x > y)); // false

Type operators are used to determine the type of a value or convert a value from one type to another. The 'typeof' operator returns the type of a value and the 'instanceof' operator checks whether an object is an instance of a specific type.

let x = "Hello, world!";
let y = new String("Hello, world!");

console.log(typeof x); // "string"
console.log(typeof y); // "object"
console.log(y instanceof String); // true

In summary, HTML, CSS and JavaScript are the three fundamental technologies for web development. Mastering these skills is essential to becoming an effective front-end developer. We hope this chapter has provided a solid introduction to HTML and JavaScript operators.

Now answer the exercise about the content:

What are JavaScript operators and what are some of the types mentioned in the text?

You are right! Congratulations, now go to the next page

You missed! Try again.

Article image Introduction to HTML: basic structure, tags and attributes: Control structures (if, switch, for, while)

Next page of the Free Ebook:

30Introduction to HTML: basic structure, tags and attributes: Control structures (if, switch, for, while)

5 minutes

Earn your Certificate for this Course for Free! by downloading the Cursa app and reading the ebook there. Available on Google Play or App Store!

Get it on Google Play Get it on App Store

+ 6.5 million
students

Free and Valid
Certificate with QR Code

48 thousand free
exercises

4.8/5 rating in
app stores

Free courses in
video, audio and text