1. Variables
A variable is a container or a coding box that is used for storage of user Information Like a real life box, Variables store different types of things or data. In computer programming we have different types of Data which are called Data types
2. Data Types
Data types are the types of information that are stored in Variables In Javascript there are 5 data types 1.Strings 2.Numbers 3.Booleans 4.Undefined 5.null
Strings: In computer programming, a string is traditionally a sequence of characters meaning: Alphanumeric set of characters. in javascript strings are written like this:
// a variable must be defined with a name and a value unless the type is 'Undefined'
var myvar = "This is a string 12345"
if you want to see the output of your code do this: Variable names should not contain: Spaces or Numbers They can only contain laetters and underscores
var myvar = "This is a string 12345"
/*console.log()is a function that will take the output of whatever is passed in between the parentheses() you can either pass a variable or directly
pass a strince like this console.log("My string")*/
console.log(myvar)
// run this code on your browser or IDE whichever is preffered
Numbers This is a variable of both Whole and Decimal numbers
// whole numbers
var mynum = 2
//decimal numbers
var mynum = 2.4
Booleans In JavaScript, a Boolean value is one that can either be TRUE or FALSE.
var myBool = true
// give your variables more user friendly names like:
var isTrue = true
var isFalse = false
Undefined and Null Undefined variables are empty variables that are not being used and have no datatype like:
//if undefined variables are put into the console they would just return the value 'undefined'
var myvar = undefined
Null Variables are variables that return the type 'Null' which means 'Empty'
var myvar = null
Variable content can be changed overtime example:
var myvar = 2
myvar = 6
console.log(myvar)
//the output would be "6"
Objects
In JavaScript, an object is a standalone entity, with properties and type. Compare it with a cup, for example. A cup is an object, with properties. A cup has a color, a design, weight, a material it is made of, etc. The same way, JavaScript objects can have properties, which define their characteristics.
var myvar = {var1: "this is a variable"
var2: "this is another variable"}
// in objects you can store other variables in a=that variable and you can access them like this
myvar.var1