Javascripting

Tram Ho

Introduction

JavaScript is a compiled, cross-platform, and interpreted programming language, also known as a scripting language for web pages. Javascript is used in web pages in addition to HTML and CSS. JavaScript can be used for client-side development as well as for server-side development. Javascript is both an imperative language and a declarative language. JavaScript contains a standard library of objects, such as Arrays, Dates, and Math, and a core set of language elements such as operators, control structures, and statements.

Valid

  • Valid are named containers for storing data values.
  • Valid is declared with the keywords var , let , const

String

  • Used to represent and manipulate a sequence of characters such as letters, numbers, punctuation, spaces,…
  • Strings are usually written in single or double quotes (‘…’,”…”).

‘this is a string’ or “this is a string”

  • Create chain

String Length

  • Check how many characters a string has using the length() property.
  • Syntax

Revising String

  • Strings have built-in functionality that allows you to inspect and manipulate their contents.
  • Sometimes we need to change the contents of a string, so to change the content in a string, we use the replace() method.
  • Syntax

Number

  • Unlike String, Number does not need to be enclosed in single or double quotes
  • Number can be an integer (1,2,3,…) or a decimal number (3.14,…)

Rounding Number

  • We can do basic math using +, -, *, / and % operators.
  • But for more complex math, we can use Math object.
  • Use Math to round numbers

Number To String

  • To convert a number to a string use the toString() method
  • The toString() method is a built-in method of the JavaScript Number object that allows you to convert any number value to its string representation.
  • For example

If Statement

  • Conditional statements are used to change the control flow of a program, based on a specified boolean condition.
  • A conditional statement has the following form

For loop

  • The for loop allows a block of code to be repeated a certain number of times.

Array

  • Array is a single variable used to store elements of different data types so that they can be accessed through a single variable.
  • Network can be created in 2 ways
  • Syntax

or

  • For example:

Array Filtering

  • To perform network filtering, we use the filter() method.
  • For example

Accessing Array Values

  • The elements of the array can be accessed through the index number.
  • Index numbers start from 0 to the array’s property length minus one.
  • The elements of the array must be accessed only through bracket notation.
  • For example

Looping through arrays

  • Use a for loop to access and manipulate a list of values ​​in a network.
  • Accessing array values ​​can be done using an integer.
  • Each item in an array is identified with a number, starting at 0
  • For example

Object

  • Object is a list of values ​​that are similar to an array, except that the values ​​are defined with keys instead of integers.

Object Properties

  • You can access and manipulate an object’s properties, the keys, and the values ​​an object contains, using a method very similar to netting.
  • For example

Object keys

  • Javascript provides a native way of enumerating all available keys of an object. This makes it possible to cycle through all the properties of an object and manipulate all their values ​​accordingly.
  • To list all object keys using Object.keys()
  • For example

Functions

  • Functions is a block that takes input, processes that input, and then produces output.
  • For example

Function Arguments

  • Function can be declared to take any number of arguments.
  • Arguments can be of any type.
  • An argument can be a number, a string, an array, an object, and even another function
  • For example

SCOPE

  • Scope is a collection of variables, objects and functions that you have access to
  • Javascript has 2 scopes: global and local
  • A variable declared outside the function definition is a global variable and its value is accessible and modifiable throughout the program.
  • The variable declared inside the function definition is a local variable, it is created and destroyed each time the function is executed, and it cannot be accessed by any code outside the function.
  • Functions defined inside other functions, called nested functions, can access the scope of their parent function.
  • For example

  • IIFE, Immediately Invoked Function Expression, is a popular pattern for creating local scopes

  • For example

 

Share the news now

Source : Viblo