DEV Community

Lourdes Suello
Lourdes Suello

Posted on

Javascript Basic

1. Data Types

  1. String "Any text"
  2. Number 12345
  3. Boolean true or false
  4. Null null
  5. Undefined undefined
  6. Symbol symbol('something')
  7. Object {key: 'value'}
    • array [1,"text", false]
    • function function name(){}

number 1-6 are six primitive types

2. Basic Vocabulary

var a = 7 + "2";

var = keyword/reserved word
any word that is part of the vocabulary of the programming languange is called a keyword(a.k.a reserve word).
Example: var = + if for...

a = variable
a named reference to a value is a variable

= and + = operator
operators are reserved-words that perform action on values and variables
Example: + - = * in === typeof != ...

var a = 7 + "2"; = statement
a group of words, numbers and operators that do a task is a statement

7 + "2" = expression
a reference, value or a group of reference(s) and value(s) combined with operator(s). which result in a single value.

3. Object
An object is a data type in Javascript that is used to store a combination of data in a simple key-value pair.

var user = {
   name: "Lourdes Suello",
   yearOfBirth: "1991"
   calculateAge: function(){
    // some code to calculate age
  }
}
Enter fullscreen mode Exit fullscreen mode

name, yearOfBirth, calculateAge = Key
these are the keys in user object.

"Lourdes Suello", "1991", function(){} = Value
these are the values of the respective keys in user object.

function(){} = Method
if a key has a function as a value its called a method

4. Function
A function is a simple bunch of code bundled in a section. This bunch of code ONLY runs when the function is called. Functions allow for organizing code into section and code reusability.

Top comments (0)