This course will be updated as we move on. It serves as an all-in guide for people new to JavaScript. I am open to directions on what the guide should cover. Thanks for reading😊
Introduction to JavaScript
Javascript
javascript, often shortened as JS, is a programming language
that is one of the core technologies of the World Wide Web (WWW),
alongside HTML and CSS. It lets us add interactivity to pages, eg.
When you click a button on different websites. All that is built using JavaScript.
Javascript is an interpreted language (or just-in-time compiled), and as you know,
it is a scripting language for the web, alongside many non-browser environments (Node.js,
Apache CouchDB and Adobe Acrobat)
Just-in-time compiled
Just-in-time or JIT compilation is a compilation of codes during the execution of a program at runtime rather than before execution.
Notes: Javascript can be executed from the browser within the terminal using Node.js.
Node.js is a Javascript runtime for running Javascript programs outside a browser environment.
Javascript as an object-oriented programming
Thus, a variable is a container for a value.
variable declaration
It is a way to let the compiler be aware of the existence of a variable within the Javascript codebase.
To declare a variable, you will need a keyword(var, let, const), variable name, and optionally initializing it to a value.
There are three ways to let the compiler be aware of the presence of a variable. These ways involve the use of keywords:
- var: A statement declares function scoped or globally scoped variables, optionally initializing each to a value.
var index = "1";
// This is a variable with a String data value.
- let: a statement that declares a reassignable block-scoped variable, optionally initializing each to a value.
let index = 2;
//This is a variable with an integer data value
- const: a block-scoped variable that cannot change value by reassignment or redeclaration. Compared to the other keywords, const must be initialized to a value.
const options = true;
//This is a variable with a boolean data value
Breakdown of a variable
Keyword (var, let, const) + variable name (letters) + assignment operator (=) + value(datatypes)
Hoisting
Hoisting is a Javascript mechanism where variable and function declarations are moved to the top of their scope before code execution.
Scopes
It refers to the visibility of a variable or how it can be used after it is declared. The scope of a variable depends on the keyword that was used to declare it.
There are three types of scopes in ES6 and they are Global scopes, Function scopes and block Scope.
Global scope: Variables declared outside any function or curly braces
{}
have a Global Scope, and can be accessed from anywhere within the same JavaScript code. var, let and const have access to this scope.Function Scope: variables within a function can only be used within the same function. Outside that function, they are undefined. var, let and const all provide this Scope.
Block Scope: A block is any part of Javascript code bounded by
{}
. Variables declared withi a block can not be accessed outside that block. This scope is only provided by the let and const keyword
Data types
Strings
Strings are characters written inside a single or double quotes. They are similarly a sequence of text (alphabetical, numeric and alphanumeric).
String Methods
Length : The length property returns the length of a string
const string1 = "Ebube";
console.log(string1.length);
at : gets the exact character per the position(index).
const string1 = "Ebube";
console.log(string1.at(0));
charAt : gets the exact character per the position(index).
const string1 = "Ebube";
console.log(string1.charAt(0));
charCodeAt: it returns the code of the character at a specified index in a string
const string1 = "Ebube";
console.log(string1.charCodeAt(0));
property access: you can access string characters through their index. Like how arrays work
const string1 = "Ebube";
console.log(string1[0]);
Top comments (0)