You get a bonus - 1 coin for daily activity. Now you have 1 coin

Introduction to data types

Lecture



  1. Data types
  2. Total

There are several basic data types in JavaScript.

Data types

  1. Number number :
    var n = 123;
    n = 12.345;
    The single type number is used for both integers and fractional numbers.

    There are special numerical values Infinity (infinity) and NaN (computation error). They also belong to the type "number".

    For example, Infinity infinity is obtained by dividing by zero:

    1 alert( 1 / 0 ); // Infinity

    The NaN calculation error will be the result of an incorrect mathematical operation, for example:

    1 alert( "нечисло" * 2 ); // NaN, ошибка

  2. String :
    var str = "Мама мыла раму" ;
    str = 'Одинарные кавычки тоже подойдут' ;
    In JavaScript, single and double quotes are equal. You can use one or the other.

    Character type does not exist, there is only a string

    Some programming languages ​​have a special data type for one character. For example, in C, this is char . In JavaScript, there is only the type "string" string . Which, I must say, is quite convenient ..

  3. Boolean (boolean) type boolean . It has only two values ​​- true (true) and false (false).

    Typically, this type is used to store a yes / no value, for example:

    var checked = true ; // поле формы помечено галочкой
    checked = false ; // поле формы не содержит галочки
    We will talk about it in more detail when we discuss logical calculations and conditional operators.

  4. null is a special value. It makes sense of “nothing.” The null value does not belong to any of the types above, but forms its own separate type consisting of a single null value:
    var age = null ;
    In JavaScript, null not a “reference to a non-existent object” or “null pointer”, as in some other languages. This is just a special meaning that makes sense of “nothing” or “value unknown”.

    In particular, the code above says that age unknown.

  5. undefined is a special value that, like null , forms its own type. It makes sense "not assigned".

    If a variable is declared, but nothing is written to it, then its value is exactly undefined :

    1 var u;
    2 alert(u); // выведет "undefined"
    You can assign undefined and explicitly, although this is rarely done:
    var x = 123;
    x = undefined ;

    In an explicit form, undefined usually not assigned, since it contradicts its meaning. To write to the "empty value" variable, use null .

  6. Objects

    The first 5 types are called "primitive" .

    The sixth type stands apart: “objects” . It includes, for example, dates, it is used for data collections and for many other things. Later we will return to this type and consider its fundamental differences from primitives.

See also

created: 2014-10-07
updated: 2023-05-14
132462



Rating 9 of 10. count vote: 2
Are you satisfied?:



Comments


To leave a comment
If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Scripting client side JavaScript, jqvery, BackBone

Terms: Scripting client side JavaScript, jqvery, BackBone