📜 ⬆️ ⬇️

Javascript from A to…

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.
  1. var numberVariable = 4;
  2. var stringVariable = "text";
  3. var arrayVariable = new Array(1, 2);
  4. //
  5. var arrayVariable2 = [1, 2];
  6. var objectVariable = new someClass();
  7. //
  8. var objectVariable2 = { 'key': 'value', key2: 'value2' }
  9. // ,
  10. // ,
* This source code was highlighted with Source Code Highlighter.

var
numberVariable = 4;
stringVariable = “text”;


:
NaN – , « » (Not a Number). , .
null – ( ).
undefined – () , ( null, , ),
Infinity — ( 1/0) ( 1602 )

NaN : parseInt(«q») + 5; // parseInt —
, undefined
  1. if( undefined === someVar )
  2. {
  3.   // ,
  4.   var someVar = 1;
  5. }
* This source code was highlighted with Source Code Highlighter.

, JS , , , ? , ? :
  1. if( undefined === window.someVar )
  2. {
  3.   // – “” window
  4.   //
  5.   var someVar = 1;
  6. }
* This source code was highlighted with Source Code Highlighter.


var: var :
  1. function makeSomeAction( someVariable )
  2. {
  3.   for( q = 0; q < 3; q++ )
  4.   {  
  5.     alert( someVariable );
  6.   }
  7. }
  8.  
  9. for( q = 0; q < 3; q++)
  10. {
  11.   makeSomeAction( q );
  12. }
* This source code was highlighted with Source Code Highlighter.

: 000111222, 000 … var , q

, (, , ),

')

Source: https://habr.com/ru/post/55799/


All Articles