I started to notice that there are articles on programming on Habré, maybe phrases like “Habr is not the same”, but this is not so important, because I like it, I always wanted to learn something new ... my first article led to a huge crash , therefore, after reading people, I will repeat my efforts and start a cycle of notes about JavaScript from the very beginning and until it is claimed =)
So part one: the basics of the basics.
To begin with, let's define my opinions: I am not a master in theory, so in order not to burden you with unnecessary names (I will indicate doubts), I will simplify a lot of things.
Data types:
boolean - a boolean value, it has 2 options, either true (true) or false (false)
number is a number, integer, or with a fractional part.
string - a string, a certain sequence of characters.
array is an array of data.
object is an object.
function is the function itself.
variables can be declared using the
var keyword.
- var numberVariable = 4;
- var stringVariable = "text";
- var arrayVariable = new Array(1, 2);
- //
- var arrayVariable2 = [1, 2];
- var objectVariable = new someClass();
- //
- var objectVariable2 = { 'key': 'value', key2: 'value2' }
- // ,
- // ,
* This source code was highlighted with Source Code Highlighter.
varnumberVariable = 4;
stringVariable = “text”;
:
NaN – , « » (Not a Number). , .
null – ( ).
undefined – () , ( null, , ),
Infinity — ( 1/0) (
1602 )
NaN : parseInt(«q») + 5; // parseInt —
,
undefined- if( undefined === someVar )
- {
- // ,
- var someVar = 1;
- }
* This source code was highlighted with Source Code Highlighter.
, JS , , , ? , ? :
- if( undefined === window.someVar )
- {
- // – “” window
- //
- var someVar = 1;
- }
* This source code was highlighted with Source Code Highlighter.
var:
var :
- function makeSomeAction( someVariable )
- {
- for( q = 0; q < 3; q++ )
- {
- alert( someVariable );
- }
- }
-
- for( q = 0; q < 3; q++)
- {
- makeSomeAction( q );
- }
* This source code was highlighted with Source Code Highlighter.
: 000111222, 000 …
var , q
, (, , ),