JavaScript Basic Syntax

Oct 10, 2023 4:35 PM

JavaScript Basic Syntax

Hello world (Printing & Commenting)

// this is a comment
console.log("Hello world")
/*
 * This is a multiline comment
*/
console.log(`This is an variable ${X} in the log  `)

Variables

#Block scope

var variable = "I can change and im hoisted" // Variable with hoisting
let myName = "I can change" // Variable with blockscope 
const myConst = "I wont change"

Const

It does not define a constant value. It defines a constant reference to a value.

Can NOT:

But you CAN:

Scope

Global scope
Scope

All scripts and functions on a web page can access it.

let carName = "Volvo";  
// code here can use carName  
  
function myFunction() {  
// code here can also use carName  
}
Block scope

let,const: Variables declared inside a { } block cannot be accessed from outside the block:
var Variables declared inside a { } block can be accessed from outside the block.

{  
  let x = 2;  
}  
// x can NOT be used here
{  
  var x = 2;  
}  
// x CAN be used here

Operators

Data Types

Number

All numbers in JS are always one type: Double (64-bit)

BigInt

String

Boolean

Undefined

Object

Null

Null vs Undefined

Symbol

Data Structures

Sets

Functions

function myFunction(param,param,...theRestOfParams){
	return param * param
}

Anonymous

Hoisting

Control Flow

Nullability

Relates to

References