JavaScript- Understanding JS Variables and Data Type Basics

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Arrays

A collection of items stored in a contiguous memory location and addressed using one or more indices where the starting index is 0.

Variable names must begin with these:

A letter, _(underscore) or $

What is a variable in programming?

A named location in memory that holds values which can be either variable mutable or immutable depending on how they are declared.

Variable names may not begin with

A number or symbols other than _ or $.

Boolean

A single value of either true or false.

Objects

An _______ is a structure of code that models real-life objects and has modifiable properties represented in key:value pairs.

Reserved Words

Another name for key words. These words are sued to create programming constructs and CANNOT be used to name variables, constants, functions, objects, etc.

parseFloat() does what?

Converts a decimal number from a string [not part of the math object].

primitive data type

Data types provided by JavaScript language that do not have methods or properties and are values that are as byte, short, int, long, float, double, char, boolean

non-primitive data types

Data types that have methods and properties assigned are are String, Arrays and Classes

data types

Every variable has a ________________________ that tells what kind of data is being stored in a variable. There are two types of data types in JavaScript namely Primitive data types and Non-primitive data types.

literals

Exact values - can be numbers , strings, Boolean values

Variables may be declared having the following names: yield, with, in, let, debugger. True or False

False: all are keywords in JavaScript

Type Casting

Forces a value of one data type to be used as a value of another data type.

Data Requirement Rules

Give information about the data in which a variable is to be declared

Dynamic Data Type

In JavaScript, a programmer does not have to declare to the program the datatype a variable will hold before it is initialized. For example in Visual Basic .Net variables are declared like this: Dim intNum As Integer before they can be initialized. This does not occur in JavaScript.

Block Scope

In a code block surrounded by { } , any variable you declare within a block is local to that block and has ____________

Numbers

Integers or decimal numbers.

undefined

Not a value but is received when a variable is declared but not yet initialized using let or var.

Strings

Pieces of text wrapped by single or double quotes and may contain letters, numbers and symbols.

typeof operator

Returns the data type of a variable or an expression

NaN

Short for not-a-number.

Symbols used to identify array data types.

Square brackets

Empty Values

String that has both a legal value and a type and is initialized to "". Ex: wkDays = "";

" " or ' '

Symbols used to surround strings.

let, var

The 2 key words that declare variables where the values are mutable.

const

The keyword that is used to declare and initialize a variable where the values are immutable.

Common Sense Variable Naming

The naming concentions for the variable name are representative of the data requirement rules and data type.

CamelCase notation

The practice of omitting spaces in compound words and starting each word with a capital letter when creating names for variables, functions, objects ,etc. Ex:firstName

Data Type Casting

The process of temporarily changing the data type of a variable for one statement.

Declaring a variable name like the following: var let; will give a compile error. True or false

True: let is a reserved JavaScript keyword so you can not use it.

The following will give compile error: var one='hello"; var two="world "; True or false

True: matching pairs must be the same i.e. ' ' and/or " "

.length property

Used to get the number of characters(length) of a string or array Ex: let dLength = dayWeek.length;

Rule-of-thumb for identifying variables that are constants

Variable names are named using all capital letters

Global Scope Variables

Variables declared in the main body of the program and so can be accessed anywhere in the code.

Local/Block Scope Variables

Variables declared within a function, method or block of code surrounded by { } and can be accessed only within that code block.

Meaningful Variable Names

Variables names that clearly tells a programmer the variables purpose and datatype.

Function Scope

Whenever you declare a variable in a function, the variable is visible only within the function. You can't access it outside the function.

mutable

changeable

Variables declared using these key words, may not be redeclared in the same scope and are immutable

const

toUpperCase() method does what?

converts all letters in a string to uppercase e.x. string.toUpperCase()

toLowerCase() method does what?

converts all letters inside a string to be all lowercase. e.x. string.toLowerCase()

parseInt() does what?

gets a number from a string [not part of the math object] parseInt(string) document.write(parseInt("45.1nn"))-->451 document.write(parseInt("45nn"))-->45

Concatenation

joining strings together using the + symbol

when assigning stings to a variable, the data is read

left to right

Key word for variables that can be declared ONLY 1 time in its scope.

let

Declare a a variable that has the value equal to null.

let name = null;

null

nothing

typeof objectdatatype

null data type

Difference between null and undefined:

null is an assigned value which means nothing. undefined is assigned to a variable has been declared but not yet initialized.

indexOf() method does?

returns the position of the first occurance of a string inside a larger string.

Special Characters

the non-alphanumeric symbols on a keyboard, such as $, @, and /, but also includes hidden characters used in software for special functions, such as a non-breaking space, backspace, tab, carriage return, etc.

immutable

unchangeable

Variables declared using this keyword may be redeclared in the program.

var

Use one statement to declare multiple variables on one line.

var one, two, three;

Use one statement to declare and initialize multiple variables on one line.

var one=1, two = 2, three =3;

index of arrays start at this number

zero

A block of code is enclosed by these symbols.

{ statements}


Set pelajaran terkait

Chapter 11: Video - Sriracha BA101

View Set

accounting chapter 7-9 multiple choice

View Set

albert personalities/testing and individual differences

View Set