JavaScript is a programming language for the web. It is one of the core technologies of the world wide web. It enables you to enables you to create dynamically updating content, control multimedia, animate images, and pretty much everything else. (Okay, not everything, but it is amazing with what one can achieve with a few lines of JavaScript code.)😀
JavaScript QuickStart Tutorial:
In this tutorial, we're gonna look at some important JavaScript data types. JavaScript have a list of data variables.
- Numbers
- Strings
- Objects
- Arrays
- Functions
A variable is a “named storage” for data. We can use variables to store goodies, visitors, and other data.
To create a variable in JavaScript, use the let keyword.
JavaScript Numbers
let x = 5; //store the Number 5 in the variable named x
let y = 2; //store the Number 2 in the variable named y
let z = x + y; //store the Number 7 in the variable named z
JavaScript Strings
Strings store text. Strings are written inside quotes. You can use single or double quotes:
let message;
Now, we can put some data into it by using the assignment operator =:
let message;
message = 'Hello!'; //store the string 'Hello!' in the variable named message
alert(message) // shows the variable content
###JavaScript Objects
An object is a non-primitive, structured data type in JavaScript. Objects are same as variables in JavaScript, the only difference is that an object holds multiple values in terms of properties and methods.
In JavaScript, an object can be created in two ways:
- using Object Literal/Initializer Syntax
using the Object() Constructor function with the new keyword.
Objects created using any of these methods are the same.
let phone1 = { model: 'Samsung' } //object literal syntax
let phone2 = new Object() //object constructor function
p2.model = 'iPhone' //property
JavaScript Arrays
JavaScript arrays are used to store multiple values in a single variable.
let phones = ['samsung', 'iPhone', 'Inifinix' ]
JavaScript Functions
A JavaScript function is a block of code designed to perform a particular task.
function myFunc(x, y) {
return x * y;
}