Introduction to modern JavaScript_
A Brief History On Javascript
JavaScript was created by Brendan Eich in 1995 it was initially known as LiveScript but later on changed to JavaScript so as to position it as a companion to java programming language.
What is JavaScript?
JavaScript is a scripting language, its one of the popular programming languages. Initially js was mainly used for making webpages interactive such as form validation, animation, etc. Nowadays, JavaScript is also used in many other areas such as server-side development, mobile app development and so on.
Basics in JavaScript
- Variables
- Datatypes
- comments
- Functions
- Objects
- Arrays
Variables
variables are containers that store data values,in JavaScript you can declare variables using 3 keyword var, let or const .JavaScript is a loosely -typed language you don't have to specify datatype when declaring variables .
var name ='jules'
const nationality = 'Kenyan'
let age = 12
Datatypes
The term datatypes refers to the type of values a program can work with.JavaScript variables can hold a number of data types
let year = 1995; // datatype is a number
let name = 'jules is a kenyan '; // datatype is a string
let isAHoliday= true // datatype boolean ,takes true or false
const price = 45.55 // datatype float ,a number with decimals
Comments
comments are block of statements that don't get executed.They make our code more readable to others so be kind and comment*smiles
// this a single line comment
/*
this is
a mutiple-line
comment
*/
*
Functions
A function is block of code that performs a specific task.
Advantages of using functions is
- Can be reused- define a code once use it many times.
- Can use the same code many times with different arguments to produce different results
function name (){
//code to be executed
}
Objects
JavaScript objects are variables that contain many values written in form of key:values
let student ={
name :'jules',
age: 12;
height: 153
}
Arrays
JavaScript arrays stores multiple values in a single variable
// empty array
const myList = [ ];
// array of numbers
const numberArray = [ 2, 4, 6, 8];
// array of strings
const stringArray = [ 'eat', 'work', 'sleep'];
// array with mixed data types
const newData = ['work', 'exercise', 1, true];
Top comments (0)