Найти в Дзене

Introduction to JavaScript

Console The console is a panel that displays important messages, like errors, for developers. Much of the work the computer does with our code is invisible to us by default.
When we write console.log() what we put inside the parentheses will get printed, or logged, to the console.
It’s going to be very useful for us to print values to the console, so we can see the work that we’re doing. console.log(5); // 5 printed Comments There are two types of code comments in JavaScript: // Prints 5 to the console
console.log(5);
console.log(5);  // Prints 5 console.log(/*IGNORED!*/ 5);  // Still just prints 5 Data types: The first 6 of those types are considered primitive data types. They are the most basic data types in the language. Arithmetic Operators An operator is a character that performs a task in our code. String Concatenation When a + operator is used on two strings, it appends the right string to the left string. // В Python пробел между сроками проставиться только при использовании фу
Оглавление
JavaScript Tutorial: Learn JavaScript For Free | Codecademy

Console

The console is a panel that displays important messages, like errors, for developers. Much of the work the computer does with our code is invisible to us by default.
When we write console.log() what we put inside the parentheses will get printed, or logged, to the console.
It’s going to be very useful for us to print values to the console, so we can see the work that we’re doing.

console.log(5); // 5 printed

Comments

There are two types of code comments in JavaScript:

  1. A single line comment == two forward slashes //
// Prints 5 to the console
console.log(5);
console.log(5);  // Prints 5
  1. A multi-line comment will comment out multiple lines and is denoted with /* to begin the comment, and */ to end the comment.
    You can also use this syntax to comment something out in the middle of a line of code:
console.log(/*IGNORED!*/ 5);  // Still just prints 5

Data types:

  • Number: Any number, including numbers with decimals: 4, 8, 1516, 23.42.
  • String: Any grouping of characters on your keyboard (letters, numbers, spaces, symbols, etc.) surrounded by single quotes: ' ... ' or double quotes " ... ", though we prefer single quotes. Some people like to think of string as a fancy word for text.
  • Boolean: This data type only has two possible values— either true or false (without quotes). It’s helpful to think of booleans as on and off switches or as the answers to a “yes” or “no” question.
  • Null: This data type represents the intentional absence of a value, and is represented by the keyword null (without quotes).
  • Undefined: This data type is denoted by the keyword undefined (without quotes). It also represents the absence of a value though it has a different use than null. undefined means that a given value does not exist.
  • Symbol: A newer feature to the language, symbols are unique identifiers, useful in more complex coding. No need to worry about these for now.
  • Object: Collections of related data.

The first 6 of those types are considered primitive data types. They are the most basic data types in the language.

Arithmetic Operators

An operator is a character that performs a task in our code.

  1. Add: +
  2. Subtract: -
  3. Multiply: *
  4. Divide: /
  5. Remainder: % /* 11 % 3 equals 2 because 3 fits into 11 three times, leaving 2 as the remainder.*/

String Concatenation

When a + operator is used on two strings, it appends the right string to the left string. // В Python пробел между сроками проставиться только при использовании функции print()

Properties

All data types have access to specific properties that are passed down to each instance. For example, every string instance has a property called length that stores the number of characters in that string. /* Как я понял, каждый представитель типа данных является частным случаем объекта. У каждого объекта (и его частного случая) есть набор черт, к которым можно получить доступ "из коробки".*/
The . is another operator! We call it the
dot operator.

Methods

Remember that methods are actions we can perform. Data types have access to specific methods that allow us to handle instances of that data type.

We call, or use, these methods by appending an instance with:

  • a period (the dot operator)
  • the name of the method
  • opening and closing parentheses
console.log('string'.toUpperCase()) ==> 'STRING'
console.log('string'.startsWith('str')) ==> boolean true /* 'str' is an input, or argument. */

Built-in Objects

In addition to console, there are other objects built into JavaScript.
The great thing about
objects is that they have methods! Let’s call the .random() method from the built-in Math object:

console.log(Math.random()); // Prints a random number between 0 and 1

This method returns a random number between 0 (inclusive) and 1 (exclusive).