Page 334 - Webapplication11_C11_Flipbook
P. 334

Non-Primitive Data Types
              Non-primitive data types (also known as reference types) are more complex types that can hold collections of values
              or more complex entities. These types are mutable (can be changed) and include:

              Ð ÐObject: A collection of key-value pairs, where keys are strings (or symbols) and values can be of any data type.
                Example:

                let person = {
                name: "Alice",
                age: 30,
                isStudent: false

                };
              Ð ÐArray: A special type of object that represents an ordered list of values.
                Example:

                let fruits = ["apple", "banana", "cherry"];
              Ð ÐFunction: Functions in JavaScript are also objects and can be assigned to variables, passed as arguments, and
                 returned from other functions.
                Example:

                function greet() {
                return "Hello!";

                }
              Ð ÐDate: Represents a date and time, allowing for easy manipulation of dates.
                Example:

                let today = new Date();
              Ð ÐRegExp: Represents a regular expression, used for pattern matching within strings.
                Example:

                let regex = /abc/;

                 4.15 STATEMENTS IN JAVASCRIPT
              Commands and instructions given to the JavaScript interpreter to take some actions are called statements and a
              collection of statements is called a script or a program. Within almost every browser resides the JavaScript interpreter.
              We use the semicolon to terminate a statement but, if the statements are written in separate lines, then the semicolon
              can be omitted.
              JavaScript statements consist of variables, keywords, operators, expressions and comments. Let us learn about them
              in detail.

              Variables

              A variable is a name of storage location. It stores a value that can be modified later. JavaScript is a loosely typed
              language which means it does not require a data type to be declared before using it. An Identifier is the name of a
              variable. Syntax to declare a variable in JavaScript is:

                var <variable name> = <value>;
              where var is a keyword, <variable name> is a valid name for the variable and <value> is the value that you want to
              assign the variable.


                332     Touchpad Web Applications-XI
   329   330   331   332   333   334   335   336   337   338   339